-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: reduce excessive MISSING_TRANSLATION warnings for fallback locales #9294
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
Changes from 2 commits
b5b945f
eb2c2bf
d58242c
1218484
27bc22a
a31ff32
f052b9a
e63d60f
1111aab
f1032c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,24 +90,35 @@ | |
| /** Base language for loading message catalogs (e.g. "en"). */ | ||
| export const currentMessageLocale = resolvedLocale.messageLocale; | ||
|
|
||
| async function loadCompiledMessages(locale: string): Promise<Record<string, string>> { | ||
| const mod = await import(`./compiled/${locale}.json`); | ||
|
Check failure on line 94 in ui/desktop/src/i18n/index.ts
|
||
| return (mod.default ?? mod) as Record<string, string>; | ||
| } | ||
|
|
||
| /** | ||
| * Load compiled messages for a given locale. | ||
| * Returns an empty object for English (react-intl uses defaultMessage as fallback). | ||
| * English messages are always loaded as the fallback catalog so regional | ||
| * English locales can keep their locale for date/number formatting without | ||
| * triggering missing translation warnings for every message. | ||
| */ | ||
| export async function loadMessages(locale: string): Promise<Record<string, string>> { | ||
| const englishMessages = await loadCompiledMessages('en'); | ||
|
|
||
| if (locale === 'en') { | ||
| // English strings live in source code as defaultMessage — no catalog needed. | ||
| return {}; | ||
| return englishMessages; | ||
| } | ||
|
|
||
| try { | ||
| // Dynamic import so compiled translation bundles are code-split. | ||
| const mod = await import(`./compiled/${locale}.json`); | ||
| return mod.default ?? mod; | ||
| const messages = await loadCompiledMessages(locale); | ||
| return { | ||
| ...englishMessages, | ||
| ...messages, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Merging Useful? React with 👍 / 👎.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }; | ||
| } catch { | ||
| console.warn( | ||
| `[i18n] No message catalog found for locale "${locale}", falling back to English.` | ||
| ); | ||
| return {}; | ||
| return englishMessages; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.