JTTranslator 1.1.1

JTTranslator 1.1.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Sep 2016
SPMSupports SPM

Maintained by Jonathan Vukovich Tribouharet.



  • By
  • Jonathan Tribouharet

JTTranslator

JTTranslator is an easy to way to manage your translations on iOS without building a new version of your app, which allow you to update your translations after having released on the AppStore.

It’s work with Translator, a platform for manage your translations on iOS and Android.

Installation

With CocoaPods, add this line to your Podfile.

pod 'JTTranslator', '~> 1.0'

Usage

You have to initialize JTTranslator with your API KEY to download your translations. The start method will automatically load the last downloaded versions of your translations and try to update them.

In your AppDelegate, just add:

import JTTranslator

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        JTTranslator.start(apiKey: "YOUR_API_KEY")
    }

}

The easiest way is to replace every call to NSLocalizedString by a global method which I call tr. This method try to get the translations from JTTranslator and the translation if is not found, it will fallback on NSLocalizedString.

If you want to do like me, you have to create this global method:

func tr (_ key: String) -> String {
    return JTTranslator.tr(key: key) ?? NSLocalizedString(key, comment: "")
}

For example, in this case if you want to manage the translations for a UILabel, you will have to do something like:

let label = UILabel()
label.text = tr("the_translation_key_you_choose")

You can also force to update the translations by calling JTTranslator.update().

Author

License

JTTranslator is released under the MIT license. See the LICENSE file for more info.