Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lang tests #5292

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lang/lang.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this was superfluous?
The intention was that it would replace whatever previous configuration was set up...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setupLang does the exact same thing, see https://github.com/fyne-io/fyne/blob/develop/lang/lang.go#L196

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, sorry for missing that - I was on my mobile

setupLang(closestSupportedLocale(all).LanguageString())
}
56 changes: 30 additions & 26 deletions lang/lang_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
andydotxyz marked this conversation as resolved.
Show resolved Hide resolved
}`)))
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) {
Expand All @@ -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))
Expand All @@ -59,22 +63,22 @@ 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"))
assert.Equal(t, "Apple Matched", X("appleID", "Apple"))
}

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))
Expand Down