SwiftyInAppLocalization which supports to switch the language at run time. Compatible with both Swift and Objective-C.
pod 'SwiftyInAppLocalization'
github "janlionly/SwiftyInAppLocalization"
- iOS: Open Xcode, File->Swift Packages, search input https://github.com/janlionly/SwiftyInAppLocalization.git, and then select Version Up to Next Major 1.0.0 < .
- Or add dependencies in your
Package.swift
:
.package(url: "https://github.com/janlionly/SwiftyInAppLocalization.git", .upToNextMajor(from: "1.0.0")),
Before do this, Firstly, you should set your localizations in your Xcode project; Secondly, add Localizable.strings and localize it.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Set you default language after launching
SwiftyInAppLocalization.shared().defaultLanguageCode = "en"
return true
}
// somewhere you want to change language call "setCurrentLanguageCode", and must reload your view controller.
let ctrl = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()!
SwiftyInAppLocalization.shared().setCurrentLanguageCode("ja", reload: ctrl) { (view) in
view.alpha = 0
}
// or set the parameter of 'reload' to nil, then you do reload your view controller by yourself
SwiftyInAppLocalization.shared().setCurrentLanguageCode(language.languageCode, reload: nil, animation: nil)
// reload your view controller here
// ...
- iOS 8.0+
- Swift 4.2 to 5.2
Visit my github: janlionly
Contact with me by email: [email protected]
I would love you to contribute to SwiftyInAppLocalization
SwiftyInAppLocalization is available under the MIT license. See the LICENSE file for more info.