Handle some Text in UIKit for different language
- Handle
.tsv
file which value in pair, in single line.
- Assign key in Interface builder, like
.storyboard
, .xib
file.
- Change all UI object text by only
LocalizedManager.shared.change(setting:)
- Add
_Language_.tsv
into Bundle
- Add case in
enum Language
, make sure system code is related.
enum Language {
case en = "_SYSTEM_LANGUAGE_CODE_"
case ch = "zh-Hant"
}
- Give the file name to the
Language
case
extension Language {
var fileName:String {
switch self {
case .en: return "en"
case .ch: return "ch"
}
}
}
- Give
localizedKey
in Interface builder for each UILabel, UIButton, UITextfield
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="localizedKey" value="hi"/>
</userDefinedRuntimeAttributes>
- Change
LocalizedManager.shared.change(setting:)
in proper way
LocalizedManager.shared.change(setting: self.language.setting)