Merge pull request #2503 from SillyTavern/fix-locale-init

Move locale file load awaits into its init function
This commit is contained in:
Cohee 2024-07-10 20:24:56 +03:00 committed by GitHub
commit 2f7a60ef36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 3 deletions

View File

@ -4,10 +4,10 @@ import { updateSecretDisplay } from './secrets.js';
const storageKey = 'language';
const overrideLanguage = localStorage.getItem(storageKey);
const localeFile = String(overrideLanguage || navigator.language || navigator.userLanguage || 'en').toLowerCase();
const langs = await fetch('/locales/lang.json').then(response => response.json());
var langs;
// Don't change to let/const! It will break module loading.
// eslint-disable-next-line prefer-const
var localeData = await getLocaleData(localeFile);
var localeData;
/**
* An observer that will check if any new i18n elements are added to the document
@ -214,7 +214,9 @@ function addLanguagesToDropdown() {
}
}
export function initLocales() {
export async function initLocales() {
langs = await fetch('/locales/lang.json').then(response => response.json());
localeData = await getLocaleData(localeFile);
applyLocale();
addLanguagesToDropdown();
updateSecretDisplay();