README.md in xcmultilingual-0.2.3 vs README.md in xcmultilingual-0.3.0

- old
+ new

@@ -1,8 +1,8 @@ # xcmultilingual -Command line tool for Swift localizations: It parses localization files in the project and output swift file including functions with pretty complementations! +Command line tool for Swift localizations: It parses localization files in the project and generate swift file including functions with neat complementations! [![Gem Version](https://badge.fury.io/rb/xcmultilingual.svg)](http://badge.fury.io/rb/xcmultilingual) [![Join the chat at https://gitter.im/morizotter/xcmultilingual](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/morizotter/xcmultilingual?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) RubyGems: [xcmultilingual](https://rubygems.org/gems/xcmultilingual) @@ -72,40 +72,60 @@ case RABBIT = "RABBIT" case RHINOCEROS = "RHINOCEROS" case GORILLA = "GORILLA" case MONKEY = "MONKEY" - func string() -> String { + var value: String { return NSLocalizedString(rawValue, tableName: Animal.name, bundle: NSBundle.mainBundle(), value: rawValue, comment: "") } static let name = "Animal" static var keys: [String] { return ["CAT", "DOG", "BEAR", "DEER", "SQUIRREL", "ELEPHANT", "GIRAFFE", "TIGER", "LION", "RABBIT", "RHINOCEROS", "GORILLA", "MONKEY"] } static var localizations: [String] { - return Animal.keys.map { Animal(rawValue: $0)!.string() } + return Animal.keys.map { Animal(rawValue: $0)!.value } } } + enum Localizable: String { + case HELLO = "HELLO" + case GOODMORNING = "GOODMORNING" + case GOODEVENING = "GOODEVENING" + + var value: String { + return NSLocalizedString(rawValue, tableName: Localizable.name, bundle: NSBundle.mainBundle(), value: rawValue, comment: "") + } + + static let name = "Localizable" + + static var keys: [String] { + return ["HELLO", "GOODMORNING", "GOODEVENING"] + } + + static var localizations: [String] { + return Localizable.keys.map { Localizable(rawValue: $0)!.value } + } + } + enum SampleSample: String { case SAMPLE = "SAMPLE" - func string() -> String { + var value: String { return NSLocalizedString(rawValue, tableName: SampleSample.name, bundle: Multilingual.bundle("sample.bundle"), value: rawValue, comment: "") } static let name = "Sample" static var keys: [String] { return ["SAMPLE"] } static var localizations: [String] { - return SampleSample.keys.map { SampleSample(rawValue: $0)!.string() } + return SampleSample.keys.map { SampleSample(rawValue: $0)!.value } } } private static func bundle(relativePath: String) -> NSBundle { @@ -140,11 +160,11 @@ Awesome! And print localized string is: ```swift -Multilingual.Animal.DOG.string() +Multilingual.Animal.DOG.value ``` Easy! ## Commands @@ -156,23 +176,23 @@ - `-template` or `-t`: Use custom template for generating swift file. You can copy original and change where you want! - `--verbose`: Output execution logs **help:** Write `update` after help and show update options' help. -If you want to use `LOC` for top level struct name. `xcmultilingual update ./DemoApp/Multilingual.swift -n LOC` and then you can write like `LOC.Animal.DOG.string()` +If you want to use `LOC` for top level struct name. `xcmultilingual update ./DemoApp/Multilingual.swift -n LOC` and then you can write like `LOC.Animal.DOG.value` ## Swift functions `Multilingual` is swift struct. Localization tables are represented as enum in this struct. -Each enum has `string()` instance function and Table `name`, `keys` and `localizations` static computed properties. +Each enum has `value` instance computed property and Table `name`, `keys` and `localizations` static computed properties. Example: When you want to use Animal table's DOG key localization. ```swift -Multilingual.Animal.DOG.string() // Dog +Multilingual.Animal.DOG.value // Dog ``` When you want to show every localizations in test. ```swift