mtpLocaleManager
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
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
- 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.
- 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.