Skip to content

Commit 2ef5f03

Browse files
committed
fix(mdviewer): strip region code from locale before loading translations
Phoenix sends full locale like "en-US" but locale files are named "en.json". Strip to base language to avoid "Failed to load locale" warnings.
1 parent bc24fdf commit 2ef5f03

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src-mdviewer/src/core/i18n.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ async function loadLocale(locale) {
3737
}
3838

3939
export async function setLocale(locale) {
40-
translations = await loadLocale(locale);
41-
setState({ locale });
40+
// Strip region code (e.g. "en-US" → "en") since locale files use base language
41+
const baseLocale = locale.split("-")[0].split("_")[0];
42+
translations = await loadLocale(baseLocale);
43+
setState({ locale: baseLocale });
4244
applyTranslations();
43-
document.documentElement.lang = locale;
44-
document.documentElement.dir = RTL_LOCALES.has(locale) ? "rtl" : "ltr";
45+
document.documentElement.lang = baseLocale;
46+
document.documentElement.dir = RTL_LOCALES.has(baseLocale) ? "rtl" : "ltr";
4547
}
4648

4749
export function t(key) {

0 commit comments

Comments
 (0)