SwiftLocalization 0.2.0

SwiftLocalization 0.2.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Aug 2016
SPMSupports SPM

Maintained by Daniel Saidi.



SwiftLocalization

SwiftLocalization is a Swift library that can be used to handle localization in iOS apps. It is currently limited to the functionality I need in my own apps. I will extend it as those apps become more sophisticated over time.

Getting started

I have currently not had time to setup a demo that shows how you build a custom tutorial on top of this library. For now, have a look at the code.

Global convenience functions

SwiftLocalization contains two global (and really simple) convenience functions:

  • translate(...) - translates a language key from Localizable.strings
  • translationExists(...) - checks if a certain language key is localized

These functions can be used instead of having to use NSLocalizedString(…) and check for equality to determine whether or not a translation exists.

Localization services

SwiftLocalization contains a LocalizationService protocol and also provides a default implementation. Using this protocol gives you a lot more flexibility in how texts are translated and locales handled.

The default implementation - LocalizationServiceDefault - can translate texts. It can also change the current locale of an app in real-time, without having to restart the app.

IMPORTANT! For LocalizationServiceDefault to work, each Localizable.strings file in the app must have a language key that indicates its locale, e.g.:

"locale": "en";

The name of this language key can be anything you like, but every file must use the same name and use it when creating an instance of LocalizationServiceDefault.

Example

To run the demo project, clone the repo, and run pod install from the Example directory before running the app. This project is currently empty and only used to verify that the pod will compile properly.

Requirements

SwiftLocalization requires iOS 8 or later.

Author

Daniel Saidi, [email protected]

License

SwiftLocalization is available under the MIT license. See the LICENSE file for more info.