diff --git a/lang/lang.go b/lang/lang.go index 6a2e58bfc7..e3ea0fe06b 100644 --- a/lang/lang.go +++ b/lang/lang.go @@ -203,7 +203,5 @@ func updateLocalizer() { fyne.LogError("Failed to load user locales", err) all = []string{"en"} } - str := closestSupportedLocale(all).LanguageString() - setupLang(str) - localizer = i18n.NewLocalizer(bundle, str) + setupLang(closestSupportedLocale(all).LanguageString()) } diff --git a/lang/lang_test.go b/lang/lang_test.go index ce76623ec8..7667c0bac2 100644 --- a/lang/lang_test.go +++ b/lang/lang_test.go @@ -3,24 +3,28 @@ package lang import ( "testing" - "fyne.io/fyne/v2" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "fyne.io/fyne/v2" ) func TestAddTranslations(t *testing.T) { - setupLang("en") err := AddTranslations(fyne.NewStaticResource("en.json", []byte(`{ - "Test": "Match" -}`))) - assert.Nil(t, err) - assert.Equal(t, "Match", L("Test")) + "Test": "Match" + }`))) + if assert.NoError(t, err) { + setupLang("en") + assert.Equal(t, "Match", L("Test")) + } err = AddTranslationsForLocale([]byte(`{ - "Test2": "Match2" -}`), "fr") - setupLang("fr") - assert.Nil(t, err) - assert.Equal(t, "Match2", L("Test2")) + "Test2": "Match2" + }`), "fr") + if assert.NoError(t, err) { + setupLang("fr") + assert.Equal(t, "Match2", L("Test2")) + } } func TestLocalize_Default(t *testing.T) { @@ -45,12 +49,12 @@ func TestLocalize_Map(t *testing.T) { } func TestLocalizePlural_Fallback(t *testing.T) { - _ = AddTranslations(fyne.NewStaticResource("en.json", []byte(`{ - "Apple": { - "one": "Apple", - "other": "Apples" - } -}`))) + require.NoError(t, AddTranslations(fyne.NewStaticResource("en.json", []byte(`{ + "Apple": { + "one": "Apple", + "other": "Apples" + } + }`)))) setupLang("en") assert.Equal(t, "Missing", N("Missing", 1)) @@ -59,9 +63,9 @@ func TestLocalizePlural_Fallback(t *testing.T) { } func TestLocalizeKey_Fallback(t *testing.T) { - _ = AddTranslations(fyne.NewStaticResource("en.json", []byte(`{ - "appleID": "Apple Matched" -}`))) + require.NoError(t, AddTranslations(fyne.NewStaticResource("en.json", []byte(`{ + "appleID": "Apple Matched" + }`)))) setupLang("en") assert.Equal(t, "Apple", X("appleIDMissing", "Apple")) @@ -69,12 +73,12 @@ func TestLocalizeKey_Fallback(t *testing.T) { } func TestLocalizePluralKey_Fallback(t *testing.T) { - _ = AddTranslations(fyne.NewStaticResource("en.json", []byte(`{ - "appleID": { - "one": "Apple", - "other": "Apples" - } -}`))) + require.NoError(t, AddTranslations(fyne.NewStaticResource("en.json", []byte(`{ + "appleID": { + "one": "Apple", + "other": "Apples" + } + }`)))) setupLang("en") assert.Equal(t, "Missing", XN("appleIDMissing", "Missing", 1))