-
Notifications
You must be signed in to change notification settings - Fork 0
Internationalization
Saleh Rahimzadeh edited this page Dec 14, 2023
·
1 revision
You can use go-words to internationalization your messages, alters and ...
Define all of your texts with suffix in source:
var source = `
# Greeting
Greeting_EN = Hello
Greeting_FA = سلام
Greeting_DE = Hallo
# Farewell
Farewell_EN = Goodbye
Farewell_FA = خداحافظ
Farewell_DE = Lebewohl
`
Define your suffix as constant and call by concatenation:
const (
EN = "_EN"
FA = "_FA"
DE = "_DE"
)
value1 := wrd.Get("Greeting" + EN)
value2 := wrd.Get("Farewell" + EN)
var lang = FA
value1 := wrd.Get("Greeting" + lang)
value2 := wrd.Get("Farewell" + lang)
Define different sources:
var sourceEN = `
Greeting = Hello
Farewell = Goodbye
`
var sourceFA = `
Greeting = سلام
Farewell = خداحافظ
`
var sourceDE = `
Greeting = Hallo
Farewell = Lebewohl
`
Define different instances for sources:
wrdEN, _ := gowords.NewWordsRepository(sourceEN, core.Separator, core.Comment)
wrdFA, _ := gowords.NewWordsRepository(sourceFA, core.Separator, core.Comment)
wrdDE, _ := gowords.NewWordsRepository(sourceDE, core.Separator, core.Comment)
value_en := wrdEN.Get("Greeting")
value_fa := wrdFA.Get("Greeting")
value_de := wrdDE.Get("Greeting")