TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Sep 2016 |
Maintained by David Jennes.
Localization system that allows language switching at runtime. Supports both code strings (NSLocalizedString) and storyboards (base internationalization).
To try the example project, just run the following command:
pod try DJLocalization
Requires iOS 6 or higher.
DJLocalization is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "DJLocalization"
For Swift, use:
pod "DJLocalization/Swift"
Important note if your project doesn't use ARC: you must add the -fobjc-arc
compiler flag to all 'DJLocalization' files in Target Settings > Build Phases > Compile Sources.
DJLocalization/DJlocalization
folder into your project.Then simply add the following import to your prefix header, or any file where you use the NSLocalizedString macro (or variants).
@import DJLocalization;
You must import the header wherever you use the NSLocalizedString macro, as this header replaces the default NSLocalizedString macro with a custom one. If you don't, runtime switching of languages won't work.
Use your normal localization workflow and everything should work correctly. For code strings use NSLocalizedString
, for storyboards use Base Internationalization.
As mentioned before, NSLocalizedString
will only work correctly if you first include the correct headers. If you want a bit more safety, the library provides some extra macros DJLocalizedString
that provide the same functionality as the overridden NSLocalizedString
macros. This way you'll get a compilation error if you forget to include the headers.
At runtime, you can switch the language at any time by setting the language property:
[DJLocalizationSystem shared].language = @"en";
Be careful to only use language codes (en, nl, fr, etc...) for localizations that exist in your project.
Views are translated on load. This means that if you switch the language at some point, only subsequently loaded views will have the correct language strings. Ideally, when you switch languages, you should pop your navigation controller to it's root view controller.
DJLocalization is brought to you by David Jennes. The code is inspired by Rolandas Razma's work with RRBaseInternationalization (especially the way to load strings for storyboard/xib views).
Props to Rolandas Razma
DJLocalization is available under the MIT license. See the LICENSE file for more info.