Fix getUserLanguagePreference to check UNCLOSEAI_LANGUAGE for intro generation

This commit is contained in:
Russell Ballestrini 2026-01-03 13:46:45 -05:00
parent 0aaba4c7c0
commit 2fecc5848a

View file

@ -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) {