要运行示例项目,请克隆仓库,并首先从 Example 目录运行 pod install
。
LocalizableUI 通过 CocoaPods 提供。要安装,只需在您的 Podfile 中添加以下行:
Carthage
pod 'LocalizableUI'
github "weiss19ja/LocalizableUI"
添加到您的 Cartfile。Swift Package Manager
dependencies: [
.package(url: "https://github.com/weiss19ja/LocalizableUI.git", from: "0.3.1")
]
对于 SegmentedControl,您可以输入由逗号分隔的 Localizable.strings 密钥数组。
BackButton 可以在之前的 ViewController 中设置。在这里,您可以使用 Storyboard 中的 ViewController 字段。
如果您正在使用 NavigationItem,这将覆盖 ViewController 的标题和 BackButton。
AlertViewController
let newLabel = UILabel(frame: frame)
newLabel.localizedKey = "LocalizedKey"
本地化密钥到文本
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
语言更改手册
extension CustomView: Localizable {
func updateLocalizedStrings() {
/// do your localization stuff
text = LocalizationManager.localizedStringFor("LocalizedKey")
}
}
作者
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 {
...
}
LocalizableUI 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。
CocoaPods 是以下团队的项目