Skip to content

Commit

Permalink
Load persisted locales.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Oct 17, 2023
1 parent bd9b086 commit 39bc15b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/db/LocalesDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/db/LocalesSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const LocalesSetting = new Setting<SupportedLocale[]>(
'locales',
false,
['en-US'],

(value) =>
Array.isArray(value) &&
value.every(
Expand Down

0 comments on commit 39bc15b

Please sign in to comment.