Skip to content

bug(i18n): loadLanguage() crashes on unsupported browser locale (missing fallback) #12735

@YeonghyeonKO

Description

@YeonghyeonKO

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

  1. Set browser language to Korean (ko), Thai (th), or any language without a corresponding locales/<lang>.json file
  2. Open Langflow
  3. 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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions