Skip to content

fix(i18n): register Chinese translations under correct Fyne bundle tag#965

Open
tofuliang wants to merge 1 commit into
dweymouth:mainfrom
tofuliang:fix/i18n-chinese-translations
Open

fix(i18n): register Chinese translations under correct Fyne bundle tag#965
tofuliang wants to merge 1 commit into
dweymouth:mainfrom
tofuliang:fix/i18n-chinese-translations

Conversation

@tofuliang

@tofuliang tofuliang commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Description

Fix Chinese (zh-Hans/zh-Hant) translations not being found by Fyne's i18n matcher.

Problem

The previous translation registration code used lang.AddTranslations() with the system locale name, which didn't match Fyne's built-in bundle tag format. When the localizer queries for 'zh', go-i18n's matcher couldn't find the registered messages.

Fix

  • Register zhHans/zhHant translations under zh-Hans/zh-Hant BCP47 locale via AddTranslationsForLocale
  • This ensures translations merge into Fyne's built-in bundle tag, allowing go-i18n matcher to find app messages

Changes

  • main.go: Update translation registration logic to use correct BCP47 locale tags
  • res/translations_test.go: Add tests for translation file existence and registration

Testing

  • Unit tests verify translation files exist and are properly registered in TranslationsInfo

@tofuliang tofuliang closed this Jun 26, 2026
@tofuliang tofuliang deleted the fix/i18n-chinese-translations branch June 26, 2026 02:52
@tofuliang tofuliang restored the fix/i18n-chinese-translations branch June 26, 2026 02:53
@tofuliang tofuliang reopened this Jun 26, 2026
Comment thread main.go Outdated
@tofuliang tofuliang force-pushed the fix/i18n-chinese-translations branch 3 times, most recently from 6859b0a to 8b5b27e Compare June 29, 2026 09:28
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>
@tofuliang tofuliang force-pushed the fix/i18n-chinese-translations branch from 8b5b27e to 0cc354b Compare June 29, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants