diff --git a/public/src/ui-translations.js b/public/src/ui-translations.js index 6ddf543..de12cc5 100644 --- a/public/src/ui-translations.js +++ b/public/src/ui-translations.js @@ -3,6 +3,7 @@ // Import translations from individual language files import { UI_TRANSLATIONS } from "./languages/index.js"; +import { normalizeLanguageCode } from "./config.js"; // Export UI_TRANSLATIONS for use in other modules export { UI_TRANSLATIONS }; @@ -22,7 +23,18 @@ export function getUIText(key, params = {}) { } // Language preference management +// Priority: window.UNCLOSEAI_LANGUAGE (forced by embed) > localStorage > "en" export function getUserLanguagePreference() { + // Check for forced language from embed config first + const rawEmbedLang = (typeof window !== "undefined" && window.UNCLOSEAI_LANGUAGE) ? window.UNCLOSEAI_LANGUAGE : null; + if (rawEmbedLang) { + const normalizedLang = normalizeLanguageCode(rawEmbedLang); + if (normalizedLang) { + return normalizedLang; + } + } + + // Fall back to localStorage try { return localStorage.getItem("uncloseai_language") || "en"; } catch (error) {