mtpLocaleManager 1.0.9

mtpLocaleManager 1.0.9

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Apr 2019
SPMSupports SPM

Maintained by mtpFontManager.



  • By
  • Mostafa Taghipour

mtpLocaleManager

CI Status Version License Platform

Android version is here

mtpLocaleManger is a locale manager for iOS:

  • Change locale at runtime
  • Supports multiple language
  • Change locale according to system locale
  • Easy to use

multi-language app

Requirements

  • iOS 8.0+
  • Xcode 9+

Installation

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

pod 'mtpLocaleManager'

Usage

  1. Add as many languages as you need to the project we have the Base language resource structure by default. Let’s add new language support. Select your project file in Project Navigator, and select your project in the project and targets list. Open Info tab, and click “+” button under Localizations section. Then choose a language you want to support from the dropdown list shown.

XCode opens a dialog showing resources to be added for the new language. Pressing the Finish button will generate these files under the new language project folder

  1. Any time you need to change the locale of the application using the following code
LocaleManager.shared.currentLocale  = Locale(identifier: /* your desired language*/ "fa") 

thats it, now run your app and enjoy it

Notification

There is a notification that fired when locale did changed

override func viewDidLoad() {
    super.viewDidLoad()
    NotificationCenter.default.addObserver(self, selector: #selector(localeDidChanged(notification:)), name: NSNotification.Name.LocaleDidChange, object: nil)
}


@objc func localeDidChanged(notification:Notification)  {
    if let locale=notification.object as? String{
        print(locale)
    }
}

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Author

Mostafa Taghipour, [email protected]

License

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