mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-24 09:49:05 +01:00
f59e1155f2
* refactor: use Object.fromEntries() instead of in-house implementation * Remove extra type assertions
18 lines
659 B
TypeScript
18 lines
659 B
TypeScript
import VueI18n from 'vue-i18n';
|
|
import { clientDb, clear, bulkSet } from '../db';
|
|
import { deepEntries, delimitEntry } from 'deep-entries';
|
|
|
|
export function setI18nContexts(lang: string, version: string, i18n: VueI18n, cleardb = false) {
|
|
return Promise.all([
|
|
cleardb ? clear(clientDb.i18n) : Promise.resolve(),
|
|
fetch(`/assets/locales/${lang}.${version}.json`)
|
|
])
|
|
.then(([, response]) => response.json())
|
|
.then(locale => {
|
|
const flatLocaleEntries = deepEntries(locale, delimitEntry) as [string, string][];
|
|
bulkSet(flatLocaleEntries, clientDb.i18n);
|
|
i18n.locale = lang;
|
|
i18n.setLocaleMessage(lang, Object.fromEntries(flatLocaleEntries));
|
|
});
|
|
}
|