Fixed option ui binidngs.
This commit is contained in:
+32
-50
@@ -13,12 +13,12 @@ class LocalizationModule extends BaseModule {
|
||||
super('localization', 'Localization');
|
||||
|
||||
// Current locale
|
||||
this.currentLocale = 'en-us';
|
||||
this.translations = {};
|
||||
this.defaultLocale = 'en-us';
|
||||
this.currentLocale = this.defaultLocale;
|
||||
this.dependencies = ['persistence-manager'];
|
||||
|
||||
// Available translations
|
||||
this.translations = {};
|
||||
|
||||
// Language names mapping
|
||||
this.languageNames = {
|
||||
'en-us': 'English (US)',
|
||||
'en-gb': 'English (UK)',
|
||||
@@ -44,41 +44,31 @@ class LocalizationModule extends BaseModule {
|
||||
try {
|
||||
this.reportProgress(10, "Initializing localization");
|
||||
|
||||
// Load default English locale
|
||||
await this.loadTranslations('en-us');
|
||||
this.reportProgress(50, "Loaded default locale");
|
||||
|
||||
// Get stored locale from persistence manager if available
|
||||
const persistenceManager = this.getModule('persistence-manager');
|
||||
let storedLocale = null;
|
||||
|
||||
if (persistenceManager) {
|
||||
try {
|
||||
storedLocale = persistenceManager.getPreference('app', 'locale');
|
||||
if (storedLocale) {
|
||||
console.log(`Localization: Found stored locale: ${storedLocale}`);
|
||||
await this.loadTranslations(storedLocale);
|
||||
this.currentLocale = storedLocale;
|
||||
} else {
|
||||
// If no stored locale, ensure English is the default and persist it
|
||||
console.log('Localization: No stored locale found, defaulting to en-us');
|
||||
await this.loadTranslations('en-us');
|
||||
persistenceManager.updatePreference('app', 'locale', 'en-us');
|
||||
persistenceManager.updatePreference('tts', 'language', 'en-us');
|
||||
this.currentLocale = 'en-us';
|
||||
}
|
||||
} catch (persistError) {
|
||||
console.warn(`Failed to load stored locale:`, persistError);
|
||||
const storedLocale = persistenceManager.getPreference('app', 'locale');
|
||||
if (storedLocale) {
|
||||
console.log(`Localization: Found stored locale: ${storedLocale}`);
|
||||
await this.loadTranslations(storedLocale);
|
||||
this.currentLocale = storedLocale;
|
||||
this.reportProgress(80, `Loaded stored locale: ${storedLocale}`);
|
||||
} else {
|
||||
// If no stored locale, ensure en-us is the default and persist it
|
||||
console.log('Localization: No stored locale found, using default en-us');
|
||||
persistenceManager.updatePreference('app', 'locale', 'en-us');
|
||||
persistenceManager.updatePreference('tts', 'language', 'en-us');
|
||||
this.currentLocale = 'en-us';
|
||||
this.reportProgress(80, "Using default locale: en-us");
|
||||
}
|
||||
} else {
|
||||
// If browser locale is available, just load it as a fallback but keep English as default
|
||||
const browserLocale = navigator.language.toLowerCase();
|
||||
if (browserLocale && browserLocale !== 'en-us') {
|
||||
try {
|
||||
this.reportProgress(50, `Loading browser locale as fallback: ${browserLocale}`);
|
||||
await this.loadTranslations(browserLocale);
|
||||
// Do NOT set browser locale as current - keep English as default
|
||||
} catch (localeError) {
|
||||
console.warn(`Failed to load browser locale ${browserLocale}:`, localeError);
|
||||
}
|
||||
}
|
||||
console.log('Localization: Persistence manager not available, using default en-us locale');
|
||||
this.reportProgress(80, "Using default locale: en-us");
|
||||
}
|
||||
|
||||
// Dispatch event to notify about loaded locale
|
||||
@@ -116,24 +106,16 @@ class LocalizationModule extends BaseModule {
|
||||
const translations = await response.json();
|
||||
this.translations[normalizedLocale] = translations;
|
||||
} else {
|
||||
// Try to load the language part only
|
||||
const langPart = normalizedLocale.split('-')[0];
|
||||
if (langPart !== normalizedLocale) {
|
||||
const langResponse = await fetch(`/locales/${langPart}.json`);
|
||||
if (langResponse.ok) {
|
||||
const translations = await langResponse.json();
|
||||
this.translations[normalizedLocale] = translations;
|
||||
} else {
|
||||
// Fallback to English
|
||||
if (normalizedLocale !== 'en-us' && normalizedLocale !== 'en') {
|
||||
await this.loadTranslations('en-us');
|
||||
this.translations[normalizedLocale] = this.translations['en-us'];
|
||||
} else {
|
||||
// If English is not found, create an empty translation set
|
||||
console.warn('English translations not found, using empty set');
|
||||
this.translations[normalizedLocale] = {};
|
||||
}
|
||||
}
|
||||
// Don't try to load language part without region (e.g., "en") - we only support full locales
|
||||
// Fallback to en-us if the requested locale isn't found
|
||||
if (normalizedLocale !== 'en-us') {
|
||||
console.warn(`Translations for ${normalizedLocale} not found, falling back to en-us`);
|
||||
await this.loadTranslations('en-us');
|
||||
this.translations[normalizedLocale] = this.translations['en-us'];
|
||||
} else {
|
||||
// If en-us is not found, create an empty translation set
|
||||
console.warn('English translations not found, using empty set');
|
||||
this.translations[normalizedLocale] = {};
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user