From 39bc15b9cb4db5222063c4c00622f88296276421 Mon Sep 17 00:00:00 2001 From: "Amy J. Ko" Date: Mon, 16 Oct 2023 19:08:19 -0700 Subject: [PATCH] Load persisted locales. --- src/db/LocalesDatabase.ts | 16 ++++++++++++---- src/db/LocalesSetting.ts | 1 - 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/db/LocalesDatabase.ts b/src/db/LocalesDatabase.ts index 48ef9db42..95cdfc83b 100644 --- a/src/db/LocalesDatabase.ts +++ b/src/db/LocalesDatabase.ts @@ -55,8 +55,10 @@ export default class LocalesDatabase { this.setting = setting; - // Load the requested locales. - this.loadLocales(locales); + // Load the requested locales, combining those given (from the browser) and those from the local storage settings. + this.loadLocales( + Array.from(new Set([...locales, ...this.setting.get()])) + ); } async refreshLocales() { @@ -79,12 +81,17 @@ export default class LocalesDatabase { // Ask fonts to load the locale's preferred fonts. Fonts.loadLocales(locales); - // Update the locales stores - this.locales.set(new Locales(this.computeLocales(), DefaultLocale)); + // Update locales + this.syncLocales(); return locales; } + syncLocales() { + // Update the locales stores + this.locales.set(new Locales(this.computeLocales(), DefaultLocale)); + } + async loadLocale( lang: SupportedLocale, refresh: boolean @@ -120,6 +127,7 @@ export default class LocalesDatabase { this.localesLoaded[lang] = promise; const locale = await promise; this.localesLoaded[lang] = locale; + return locale; } catch (_) { this.localesLoaded[lang] = undefined; diff --git a/src/db/LocalesSetting.ts b/src/db/LocalesSetting.ts index d93ade0d8..7dba3cb05 100644 --- a/src/db/LocalesSetting.ts +++ b/src/db/LocalesSetting.ts @@ -5,7 +5,6 @@ export const LocalesSetting = new Setting( 'locales', false, ['en-US'], - (value) => Array.isArray(value) && value.every(