fix(i18n): register Chinese translations under correct Fyne bundle tag - #965
fix(i18n): register Chinese translations under correct Fyne bundle tag#965tofuliang wants to merge 4 commits into
Conversation
8b5b27e to
0cc354b
Compare
|
Thanks for the feedback. I have pushed a simplified revision:
Verification: |
Fix test file names to match actual files on disk (zhHans.json not zh-Hans.json). Register translations under BOTH the system locale (original trick to ensure configured language always takes effect) AND the BCP47 locale (so go-i18n's matcher correctly resolves queries like 'zh' → 'zh-Hans' for Chinese). Add BCP47Locale field to TranslationInfo struct for explicit locale mapping (zhHans→zh-Hans, zhHant→zh-Hant, pt_BR→pt-BR, etc.). Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
03c22d6 to
ef5c9fe
Compare
|
That's not just mislabeling — Since the translation files are now canonically named, this can key off the selected translation instead of the OS locale, which fixes the clobbering and also drops the func addTranslationsForConfiguredLanguage(content []byte, tr res.TranslationInfo) error {
systemLocale := lang.SystemLocale()
if err := lang.AddTranslations(fyne.NewStaticResource(systemLocale.LanguageString()+".json", content)); err != nil {
return err
}
// Translation filenames are canonical BCP47 tags (e.g. "zh-Hans.json"), so
// also register directly under that tag. This lets an explicitly selected
// Chinese variant correctly override Fyne's built-in zh-Hans/zh-Hant script
// bundle, regardless of what script the OS locale implies.
locale := strings.TrimSuffix(tr.TranslationFileName, ".json")
if locale != "zh-Hans" && locale != "zh-Hant" {
return nil
}
return lang.AddTranslationsForLocale(content, fyne.Locale(locale))
}(call site becomes I'd avoid just deleting the second registration to sidestep this — that reverts to exactly the single system-locale trick the original bug report described as broken for Chinese ("didn't match Fyne's built-in bundle tag format... go-i18n's matcher couldn't find the registered messages"), which would likely reopen the issue for anyone manually selecting a Chinese language on a Chinese-locale system. Non-Chinese language selection (e.g. Spanish on an Might also be worth strengthening |
|
Claude suggested one fix above. If this seems valid to you, you can go ahead and implement it, but if not, let me know and I'll merge it as-is |
|
Implemented the selected-script fix and strengthened the regression in commit 9433ef8. The canonical filename now determines the selected script. One additional detail was necessary for the explicit opposite-script case: Fyne's localizer still follows the OS-inferred Chinese script, so translated app messages are also registered into that active alias. Identity entries such as Verification:
|
- Load and register translations from Fyne complete preference list. - Register the configured translation under canonical, region, base, and language-script tags for each preference, without hardcoding language-specific scripts. - Replace identity placeholders with pre-registration Fyne values and drop keys where Fyne has no translation, protecting shared UI strings. - Add focused unit tests for the locale plan, alias payload, and the zh-CN/zh-Hant override case. - Validate all translation filenames as canonical BCP47 locales.
|
Simplified the implementation and removed Chinese-specific logic:
|
Description
Preserve Fyne translations when an explicitly selected language does not match the OS-inferred system locale.
Problem
When the OS locale implies one Chinese script but the user explicitly selects the other in Settings, or when any language is selected on a system where Fyne's active locale uses a different preference order, application UI strings would either fall back to English or clobber Fyne's built-in shared translations.
Fix
go-locale.GetLocales()), matching the same source Fyne uses for its active bundle.Zzzzscript inference; the solution now generalizes to all languages.Testing
go test ./...passes: 45 tests across 27 packages.