Sharkey/src/client/scripts/set-i18n-contexts.ts
tamaina 3963ed8ff7
feat(client): 翻訳をIndexedDBに保存・プッシュ通知を翻訳 (#6396)
* wip

* tabun ok

* better msg

* oops

* fix lint

* Update gulpfile.ts

Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>

* Update src/client/scripts/set-i18n-contexts.ts

Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>

* refactor

Co-authored-by: acid-chicken <root@acid-chicken.com>

* 

* wip

* fix lint

* たぶんおk

* fix flush

* Translate Notification

* remove console.log

* fix

* add notifications

* remove san

* wip

* ok

* ✌️

* Update src/prelude/array.ts

Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>

* wip

* i18n refactor

* Update init.ts

* ✌️

Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
Co-authored-by: syuilo <syuilotan@yahoo.co.jp>
2020-05-23 13:19:31 +09:00

18 lines
703 B
TypeScript

import VueI18n from 'vue-i18n';
import { clientDb, clear, bulkSet } from '../db';
import { deepEntries, delimitEntry } from 'deep-entries';
import { fromEntries } from '../../prelude/array';
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, fromEntries(flatLocaleEntries));
});
}