Latest 1.1.0
License MIT
Platforms ios 8.0

Build Status

[method swizzling]:

MHLocalizationKit is an utility and infrastructure library that can be used for runtime language changes by modifying the behavior of the standard iOS localization system and using the same translation resources.

In short – you continue to use .strings files and NSLocalizedString macros/functions with the ability to specify and change the language at runtime.

How it works

The standard NSLocalizedString macros/functions are actually using the Bundle.localizedString(forKey:value:table:). Internally this method loads the needed .strings files based on the system’s language.

What this library does is, by using [method swizzling], to alter the default behaviour of Bundle to force it to load .strings from a bundle pointing directly to the directory of the .strings files for the applied language at runtime.




Add github "KoCMoHaBTa/MHLocalizationKit" to your Cartfile, then [Embed] the framework directly into your project.


Add pod 'MHLocalizationKit' to your Podfile


Add a submodule to your repostiroy, then [Embed] the framework directly into your project


Download, then [Embed] the framework directly into your project

How to use


  • in you UIViewController subclasses that you wish to handle runtime language changes – conform to the Localizable protocol
  • implement languageDidChange(from:to:) and load your localized string from there using the standard NSLocalizedString macros/functions.
  • when your app launches – set the desired value to Bundle.language – this will call languageDidChange(from:to:) on all alive view controllers that conform to the Localizable protocol.

NSLocalizedString functions

In Swift the NSLocalizedString macros are not available, but instead there is only single NSLocalizedString function that provies the same behaviour with default arguments – genstrings is not able to parse it properly.

In order to solve this issue, this framework introduces, as substitute, the following Swift overloads that are parsed by genstrings correctly:

  • NSLocalizedStringFromTable(_:_:_:)
  • NSLocalizedStringWithDefaultValue(_:_:_:_:_:)


The language setting is persisted between application launches.

UIViewController subclasses that conforms to Localizable protocol will receive languageDidChange(from:to) call automatically upon viewDidLoad(). This is achieved using [method swizzling].

You could opt-in for automatic system language and locale tracking by setting to true respectively Bundle.trackSystemLanguageChanges and Bundle.trackSystemLocaleChanges

You could subscribe for language change notifications by using LanguageWillChangeNotificationName and LanguageDidChangeNotificationName



  • initial documented version

Latest podspec

    "name": "MHLocalizationKit",
    "version": "1.1.0",
    "source": {
        "git": "",
        "tag": "1.1.0"
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": "Milen Halachev",
    "summary": "Changing languages while your iOS application is running.",
    "homepage": "",
    "swift_version": "5.0",
    "platforms": {
        "ios": "8.0"
    "source_files": [
    "public_header_files": "MHLocalizationKit/**/*.h"

Pin It on Pinterest

Share This