Description
loadLanguage() in src/frontend/src/i18n.ts throws an unhandled runtime error when the browser's language doesn't match any available locale file. This crashes the app on startup.
Steps to Reproduce
- Set browser language to Korean (
ko), Thai (th), or any language without a corresponding locales/<lang>.json file
- Open Langflow
- App fails to load with:
Uncaught (in promise) Error: Unknown variable dynamic import: ./locales/ko.json
Root Cause
loadLanguage() uses a bare dynamic import without error handling:
export async function loadLanguage(lang: string): Promise<void> {
if (lang === "en") return;
if (i18n.hasResourceBundle(lang, "translation")) return;
const messages = await import(`./locales/${lang}.json`); // throws if file missing
i18n.addResourceBundle(lang, "translation", messages.default);
}
When index.tsx detects the browser language via navigator.language.split("-")[0] and calls loadLanguage(), the Vite dynamic import fails because the locale file doesn't exist. Since fallbackLng: "en" is configured in i18next but the import itself throws before reaching i18next, the fallback never triggers.
Note: #12671 disabled automatic browser language detection, but this issue still affects:
- Users who manually select an unsupported language
- Users with a stale
languagePreference in localStorage
- Any edge case where
loadLanguage() is called with a language code that has no locale file
Expected Behavior
The app should gracefully fall back to English when the requested locale file is missing.
Suggested Fix
Wrap the dynamic import in a try-catch:
export async function loadLanguage(lang: string): Promise<void> {
if (lang === "en") return;
if (i18n.hasResourceBundle(lang, "translation")) return;
try {
const messages = await import(`./locales/${lang}.json`);
i18n.addResourceBundle(lang, "translation", messages.default);
} catch {
console.warn(`Locale "${lang}" not found, falling back to English`);
}
}
Related
Environment
- Langflow v1.9.0
- Any browser with a non-supported language preference
Description
loadLanguage()insrc/frontend/src/i18n.tsthrows an unhandled runtime error when the browser's language doesn't match any available locale file. This crashes the app on startup.Steps to Reproduce
ko), Thai (th), or any language without a correspondinglocales/<lang>.jsonfileRoot Cause
loadLanguage()uses a bare dynamic import without error handling:When
index.tsxdetects the browser language vianavigator.language.split("-")[0]and callsloadLanguage(), the Vite dynamic import fails because the locale file doesn't exist. SincefallbackLng: "en"is configured in i18next but the import itself throws before reaching i18next, the fallback never triggers.Note: #12671 disabled automatic browser language detection, but this issue still affects:
languagePreferenceinlocalStorageloadLanguage()is called with a language code that has no locale fileExpected Behavior
The app should gracefully fall back to English when the requested locale file is missing.
Suggested Fix
Wrap the dynamic import in a try-catch:
Related
chore(i18n): disable automatic browser language detection99ee7a31—feat(i18n): lazy-load non-English locale files via Vite dynamic importsEnvironment