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>
This commit is contained in:
@ -7,13 +7,13 @@ import Vuex from 'vuex';
|
||||
import VueMeta from 'vue-meta';
|
||||
import PortalVue from 'portal-vue';
|
||||
import VAnimateCss from 'v-animate-css';
|
||||
import VueI18n from 'vue-i18n';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
|
||||
import i18n from './i18n';
|
||||
import VueHotkey from './scripts/hotkey';
|
||||
import App from './app.vue';
|
||||
import MiOS from './mios';
|
||||
import { version, langs, instanceName } from './config';
|
||||
import { version, langs, instanceName, getLocale } from './config';
|
||||
import PostFormDialog from './components/post-form-dialog.vue';
|
||||
import Dialog from './components/dialog.vue';
|
||||
import Menu from './components/menu.vue';
|
||||
@ -21,12 +21,15 @@ import { router } from './router';
|
||||
import { applyTheme, lightTheme } from './theme';
|
||||
import { isDeviceDarkmode } from './scripts/is-device-darkmode';
|
||||
import createStore from './store';
|
||||
import { clientDb, get, count } from './db';
|
||||
import { setI18nContexts } from './scripts/set-i18n-contexts';
|
||||
|
||||
Vue.use(Vuex);
|
||||
Vue.use(VueHotkey);
|
||||
Vue.use(VueMeta);
|
||||
Vue.use(PortalVue);
|
||||
Vue.use(VAnimateCss);
|
||||
Vue.use(VueI18n);
|
||||
Vue.component('fa', FontAwesomeIcon);
|
||||
|
||||
require('./directives');
|
||||
@ -96,27 +99,6 @@ if (isMobile || window.innerWidth <= 1024) {
|
||||
head.appendChild(viewport);
|
||||
}
|
||||
|
||||
//#region Fetch locale data
|
||||
const cachedLocale = localStorage.getItem('locale');
|
||||
|
||||
if (cachedLocale == null) {
|
||||
fetch(`/assets/locales/${lang}.${version}.json`)
|
||||
.then(response => response.json()).then(locale => {
|
||||
localStorage.setItem('locale', JSON.stringify(locale));
|
||||
i18n.locale = lang;
|
||||
i18n.setLocaleMessage(lang, locale);
|
||||
});
|
||||
} else {
|
||||
// TODO: 古い時だけ更新
|
||||
setTimeout(() => {
|
||||
fetch(`/assets/locales/${lang}.${version}.json`)
|
||||
.then(response => response.json()).then(locale => {
|
||||
localStorage.setItem('locale', JSON.stringify(locale));
|
||||
});
|
||||
}, 1000 * 5);
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//#region Set lang attr
|
||||
const html = document.documentElement;
|
||||
html.setAttribute('lang', lang);
|
||||
@ -167,6 +149,18 @@ os.init(async () => {
|
||||
});
|
||||
//#endregion
|
||||
|
||||
//#region Fetch locale data
|
||||
const i18n = new VueI18n();
|
||||
|
||||
await count(clientDb.i18n).then(async n => {
|
||||
if (n === 0) return setI18nContexts(lang, version, i18n);
|
||||
if ((await get('_version_', clientDb.i18n) !== version)) return setI18nContexts(lang, version, i18n, true);
|
||||
|
||||
i18n.locale = lang;
|
||||
i18n.setLocaleMessage(lang, await getLocale());
|
||||
});
|
||||
//#endregion
|
||||
|
||||
if ('Notification' in window && store.getters.isSignedIn) {
|
||||
// 許可を得ていなかったらリクエスト
|
||||
if (Notification.permission === 'default') {
|
||||
@ -176,6 +170,7 @@ os.init(async () => {
|
||||
|
||||
const app = new Vue({
|
||||
store: store,
|
||||
i18n,
|
||||
metaInfo: {
|
||||
title: null,
|
||||
titleTemplate: title => title ? `${title} | ${(instanceName || 'Misskey')}` : (instanceName || 'Misskey')
|
||||
@ -183,7 +178,8 @@ os.init(async () => {
|
||||
data() {
|
||||
return {
|
||||
stream: os.stream,
|
||||
isMobile: isMobile
|
||||
isMobile: isMobile,
|
||||
i18n // TODO: 消せないか考える SEE: https://github.com/syuilo/misskey/pull/6396#discussion_r429511030
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
|
Reference in New Issue
Block a user