xcmultilingualSwift 本地化的命令行工具
xcmultilingual 是用于 Swift 本地化的命令行工具。它分析项目中的本地化文件,和输出包含有补充的函数的转移文件。
代码示例:
import Foundation struct Multilingual { enum Animal: String { case CAT = "CAT" case DOG = "DOG" case BEAR = "BEAR" case DEER = "DEER" case SQUIRREL = "SQUIRREL" case ELEPHANT = "ELEPHANT" case GIRAFFE = "GIRAFFE" case TIGER = "TIGER" case LION = "LION" case RABBIT = "RABBIT" case RHINOCEROS = "RHINOCEROS" case GORILLA = "GORILLA" case MONKEY = "MONKEY" func string() -> String { return NSLocalizedString(rawValue, tableName: "Animal", bundle: NSBundle.mainBundle(), value: "\(rawValue)", comment: "") } static func keys() -> [String] { return ["CAT", "DOG", "BEAR", "DEER", "SQUIRREL", "ELEPHANT", "GIRAFFE", "TIGER", "LION", "RABBIT", "RHINOCEROS", "GORILLA", "MONKEY"] } static func localizations() -> [String] { return Animal.keys().map { Animal(rawValue: $0)!.string() } } } enum Localizable: String { case HELLO = "HELLO" case GOODMORNING = "GOODMORNING" case GOODEVENING = "GOODEVENING" func string() -> String { return NSLocalizedString(rawValue, tableName: "Localizable", bundle: NSBundle.mainBundle(), value: "\(rawValue)", comment: "") } static func keys() -> [String] { return ["HELLO", "GOODMORNING", "GOODEVENING"] } static func localizations() -> [String] { return Localizable.keys().map { Localizable(rawValue: $0)!.string() } } } private static func bundle(relativePath: String) -> NSBundle { var components = (__FILE__ as String).pathComponents components.removeLast() let bundlePath = join("/", components) + "/" + relativePath return NSBundle(path: bundlePath) ?? NSBundle.mainBundle() } }
评论