To run the example project, clone the repo, and run pod install
from the Example directory first.
- UIBarButtonItem
- UIButton
- UILabel
- UINavigationItem
- UISegmentedControl
- UITabBarItem
- UITableViewCell
- UITextField
- UITextView
- UIView
- UIViewController
- UIAlertController
- UIAlertAction
- iOS 9.0+
- Xcode 9.0+
- Swift 4.0+
- If you find any useful element missing please open an issue.
- If you found a bug, open an issue.
- If you want to contribute, submit a pull request.
LocalizableUI is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'LocalizableUI'
Add github "weiss19ja/LocalizableUI"
to your Cartfile.
dependencies: [
.package(url: "https://github.com/weiss19ja/LocalizableUI.git", from: "0.3.1")
]
The easiest way to use LocalizableUI is the Storyboard. Here you can enter your Localizable.strings Keys.
For the SegmentedControl you can enter an array of Localizable.strings Keys separated by ",".
The BackButton can be set in the prior ViewController. Here you can use the ViewController fields in the Storyboard.
If you are using an NavigationItem this will override the Title and the BackButton of the ViewController.
It is also possible to set the LocalizableKeys in the Code. This includes all features of the Stotyboard LocalizableKeys
let newLabel = UILabel(frame: frame)
newLabel.localizedKey = "LocalizedKey"
AlertViews must be configured in the code.
let alertController = UIAlertController(localizedTitle: Constants.titleKey, localizedMessage: Constants.messagekey, preferredStyle: .alert)
let action = UIAlertAction(localzedTitleKey: Constants.buttonKey, style: .cancel, handler: nil)
alertController.addAction(action)
// #1
let localizedText = LocalizationManager.localizedStringFor("LocalizedKey")
// #2
let localizedText = LocalizationManager.localizedStringFor("LocalizedKey", bundle: bundle, value: "", comment: "")
// #3
let localizedText = "LocalizedKey".localized
To localize any class or struct you can simply implement the Localizable Protocol
extension CustomView: Localizable {
func updateLocalizedStrings() {
/// do your localization stuff
text = LocalizationManager.localizedStringFor("LocalizedKey")
}
}
You can change the language while the app is active. You simply have to use the LocalizationManager changeLanguage(...) method. All your Views will update without any further adjustments.
do {
let tableName = "Localizable"
let bundle = Bundle(for: type(of: self))
let languageCode = "en"
try LocalizationManager.sharedInstance.changeLanguage(to: tableName, from: bundle, languageCode: languageCode)
} catch {
...
}
Jan Weiß, Philipp Weiß
LocalizableUI is available under the MIT license. See the LICENSE file for more info.