目录
目录README.md

Swift Swift 5.1 Swift Package Manager

Typed Translations

this swift package will make it easy to enable typed access to your literals specified in the Localizable.strings file.

Quick run

swift run -c release TypedTranslations Localizable.strings

What to expect?

You can expect easy typed access to your translations like it should be. No hassle with typos or missing translations anymore. Enjoy!

Usage from XCode

Input

"welcomeText" = "Hello %@, welcome in our app.";
"close" = "Close";

Output

//
//  Localizations.swift
//
//  Generated code that contains the available keys from en.lproj/Localizable.strings
//  Copyright © 2020. All rights reserved.
//

import Foundation

extension String {
    func localized(bundle: Bundle = .main, tableName: String = "Localizable") -> String {
        NSLocalizedString(self, tableName: tableName, bundle: bundle, value: self, comment: "")
    }

    func localizedWithFormat(bundle: Bundle = .main, tableName: String = "Localizable", args: CVarArg...) -> String {
        String.localizedStringWithFormat(self.localized(bundle: bundle, tableName: tableName), args)
    }
}

struct Localizations {

    private init() {}

    /// Base translation: Hello %@, welcome in our app.
    static func welcomeText(args: CVarArg...) -> String {
        "welcomeText".localizedWithFormat(args: args)
    }
    /// Base translation: Close
    static let close = "close".localized()
}

Just include this generated file in your XCode project and rerun the script whenever the .strings file is updated.

Where is my XCode project?

  • Run open Package.swift to open this swift package.

Tests

For running tests, just run swift test.

关于
155.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号