DJLocalization 1.2.2

DJLocalization 1.2.2

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Sep 2016

Maintained by David Jennes.



  • By
  • David Jennes

DJLocalization

Version License Platform

Localization system that allows language switching at runtime. Supports both code strings (NSLocalizedString) and storyboards (base internationalization).

Demo

To try the example project, just run the following command:

pod try DJLocalization

Requirements

Requires iOS 6 or higher.

Installation

From CocoaPods

DJLocalization is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "DJLocalization"

For Swift, use:

pod "DJLocalization/Swift"

Manually

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.

  • Drag the DJLocalization/DJlocalization folder into your project.

Usage

Importing headers

Then simply add the following import to your prefix header, or any file where you use the NSLocalizedString macro (or variants).

@import DJLocalization;
Important:

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.

Localization

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.

Switching languages

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.

Important:

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.

Credits

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

License

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