/runTimeLanguageChange

Change all Text-related UI object

Primary LanguageSwift

Handle some Text in UIKit for different language

Ability

  1. Handle .tsv file which value in pair, in single line.
  2. Assign key in Interface builder, like .storyboard, .xib file.
  3. Change all UI object text by only LocalizedManager.shared.change(setting:)

Usage:

  1. Add _Language_.tsv into Bundle
hi	hello
bye	bye bye
  1. Add case in enum Language, make sure system code is related.
enum Language {
	case en = "_SYSTEM_LANGUAGE_CODE_"
	case ch = "zh-Hant"
}
  1. Give the file name to the Language case
extension Language {
	var fileName:String {
		switch self {
			case .en: return "en"
			case .ch: return "ch"
		}
	}
}
  1. Give localizedKey in Interface builder for each UILabel, UIButton, UITextfield
<userDefinedRuntimeAttributes>
	<userDefinedRuntimeAttribute type="string" keyPath="localizedKey" value="hi"/>
</userDefinedRuntimeAttributes>
  1. Change LocalizedManager.shared.change(setting:) in proper way
	LocalizedManager.shared.change(setting: self.language.setting)

todo:

  • To SPM