LanguageKit is an iOS library for easy switch between different language. It use a CSV file for easy editing and sharing strings.
Work-in-progress, may not work as expected.
- Strings file based on CSV
- Programmatically or Storyboard
- Auto update when switch between UIViewControllers
To run the example project, clone the repo, and run pod install
from the Example directory first.
LanguageKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'LanguageKit'
You need a string file in CSV format, like the one below.
A example had included in the example project. (Localizable.csv)
|Key|en|zh-Hant|zh-Hans|ja| | ------------- |-------------| -----| |language.name|English|繁體中文|简体中文|日本語| |button|Button|按鍵|按键|ボタン|
The locale name (en-US/zh-Hant) does not really matter, just for your own reference. You can have anything including two different versions of en-US.
It is recommended to use a key for each string, however it's also possible to translate between strings.
In your AppDelegate:
LanguageKit.shared.setup(filename: "Localizable.csv") //or your own strings file
LanguageKit.shared.setLanguage(language: "en-US") //setup language
To use it:
"button".localized
LanguageKit.shared.setLanguage(language: "ja")
LanguageKit will lookup the string you provided and return the translated version.
If you are using UIViewController or UITableViewController, or inherit from them. a custom IBOutlet - languageComponent is created for you. Just link controls with it and you are good to go.
Supported UIControl:
- UILabel
- UIButton
- UISearchBar (Placeholder)
- UITextField (Placeholder)
- UISegmentControl
- UITabBar
- UINavigationBar's titleItem
There are two types of the language system included in the library:
You can switch langauge on the fly, the
There are numbers of components in a app that is not runtime changeble (e.g. Default UINavigationController Back button, SafariWebViewController, Permission Dialog etc.)
If you need to localized these, you need to use
LanguageKit.shared.setLanguage(language: "ja", asSystemLanguage: true)
This will brings up a dialog to notify an app restart.
Gary Law, gary@garylaw.me, @garyworks
LanguageKit is available under the MIT license. See the LICENSE file for more info.