Skip to content

mtpLocaleManager is the best choice for you if you want to change the locale at runtime and have a multi-language app

License

Notifications You must be signed in to change notification settings

MostafaTaghipour/mtpLocaleManager

Repository files navigation

mtpLocaleManager

CI Status Version License Platform

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, mostafa@taghipour.me

License

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

About

mtpLocaleManager is the best choice for you if you want to change the locale at runtime and have a multi-language app

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published