package translation_test import ( "testing" "git.apihub24.de/admin/translation" exampletranslations "git.apihub24.de/admin/translation/example_translations" ) func Test_Translation_Init(t *testing.T) { translation.Init(exampletranslations.Files) if translation.Get("KEY", "de") != "WERT" { t.Errorf("translations not initialized!") } } func Test_Translation_Get_de(t *testing.T) { translation.Init(exampletranslations.Files) value := translation.Get("KEY", "de") if value != "WERT" { t.Errorf("expect German KEY to have Value 'WERT' but was %s", value) } } func Test_Translation_Get_en(t *testing.T) { translation.Init(exampletranslations.Files) value := translation.Get("KEY", "en") if value != "VALUE" { t.Errorf("expect English KEY to have Value 'VALUE' but was %s", value) } } func Test_Translation_Get_fr(t *testing.T) { translation.Init(exampletranslations.Files) value := translation.Get("KEY", "fr") if value != "VALEUR" { t.Errorf("expect France KEY to have Value 'VALEUR' but was %s", value) } } func Test_Translation_Get_Fallback_en(t *testing.T) { translation.Init(exampletranslations.Files) value := translation.Get("KEY", "notexists") if value != "VALUE" { t.Errorf("expect Fallback KEY to have Value 'VALUE' but was %s", value) } } func Test_Translation_Can_Change_Fallback_Language(t *testing.T) { translation.Init(exampletranslations.Files) translation.SetDefaultCulture("de") value := translation.Get("KEY", "notexists") if value != "WERT" { t.Errorf("expect Fallback KEY to have Value 'WERT' but was %s", value) } } func Test_Translation_Get_With_Parameter(t *testing.T) { translation.Init(exampletranslations.Files) valueDe := translation.Get("WITH_PARAM", "de", "a", "b") valueEn := translation.Get("WITH_PARAM", "en", "a", "b") valueFr := translation.Get("WITH_PARAM", "fr", "a", "b") if valueDe != "WERT a_b" { t.Errorf("expect German KEY to have Value 'WERT a_b' but was %s", valueDe) } if valueEn != "VALUE a_b" { t.Errorf("expect English KEY to have Value 'VALUE a_b' but was %s", valueEn) } if valueFr != "VALEUR a_b" { t.Errorf("expect France KEY to have Value 'VALEUR a_b' but was %s", valueFr) } }