- add translate files in a dir,default is ./config/i18n filename should be language code like 'en', 'zh'
en.yaml
test:
name: Test
zh.yaml
test:
name: 测试
- just use
// Test in English is Test
// Test in Chinese is 测试
func useYaml() {
i := i18n.I18n{}
i.SetLang("en")
i.SetTransFilePath("./config/i18n")
i.SetTransFileType("yaml")
enStr := i.Trans("test.name").ToStr()
i.SetLang("zh")
zhStr := i.Trans("test.name").ToStr()
fmt.Printf("Test in English is %s\n", enStr)
fmt.Printf("Test in Chinese is %s\n", zhStr)
}