@@ -47,6 +47,10 @@ import (
4747 " fmt"
4848
4949 " github.com/go-playground/locales"
50+ " github.com/go-playground/locales/en"
51+ " github.com/go-playground/locales/en_CA"
52+ " github.com/go-playground/locales/fr"
53+ " github.com/go-playground/locales/nl"
5054 " github.com/go-playground/universal-translator"
5155)
5256
@@ -56,8 +60,8 @@ var universalTraslator *ut.UniversalTranslator
5660func main () {
5761
5862 // NOTE: this example is omitting allot of error checking for brevity
59-
60- universalTraslator, _ = ut.New (" en " , " en " , " en_CA" , " nl " , " fr " )
63+ e := en. New ()
64+ universalTraslator = ut.New (e, e, en_CA. New (), nl. New (), fr. New () )
6165
6266 en := universalTraslator.GetTranslator (" en" )
6367
@@ -72,21 +76,22 @@ func main() {
7276 fmt.Println (" Range Plural Rules:" , en.PluralsRange ())
7377
7478 // add basic language only translations
75- en.Add (" welcome" , " Welcome {0} to our test" )
79+ // last param indicates if it's ok to override the translation if one already exists
80+ en.Add (" welcome" , " Welcome {0} to our test" , false )
7681
7782 // add language translations dependant on cardinal plural rules
78- en.AddCardinal (" days" , " You have {0} day left to register" , locales.PluralRuleOne )
79- en.AddCardinal (" days" , " You have {0} days left to register" , locales.PluralRuleOther )
83+ en.AddCardinal (" days" , " You have {0} day left to register" , locales.PluralRuleOne , false )
84+ en.AddCardinal (" days" , " You have {0} days left to register" , locales.PluralRuleOther , false )
8085
8186 // add language translations dependant on ordinal plural rules
82- en.AddOrdinal (" day-of-month" , " {0}st" , locales.PluralRuleOne )
83- en.AddOrdinal (" day-of-month" , " {0}nd" , locales.PluralRuleTwo )
84- en.AddOrdinal (" day-of-month" , " {0}rd" , locales.PluralRuleFew )
85- en.AddOrdinal (" day-of-month" , " {0}th" , locales.PluralRuleOther )
87+ en.AddOrdinal (" day-of-month" , " {0}st" , locales.PluralRuleOne , false )
88+ en.AddOrdinal (" day-of-month" , " {0}nd" , locales.PluralRuleTwo , false )
89+ en.AddOrdinal (" day-of-month" , " {0}rd" , locales.PluralRuleFew , false )
90+ en.AddOrdinal (" day-of-month" , " {0}th" , locales.PluralRuleOther , false )
8691
8792 // add language translations dependant on range plural rules
8893 // NOTE: only one plural rule for range in 'en' locale
89- en.AddRange (" between" , " It's {0}-{1} days away" , locales.PluralRuleOther )
94+ en.AddRange (" between" , " It's {0}-{1} days away" , locales.PluralRuleOther , false )
9095
9196 // now lets use the translations we just added, in the same order we added them
9297
0 commit comments