From 9dacf11702dc9f71447bc15f1b98ab5532e46f27 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 22 Jan 2023 16:52:15 +0900 Subject: [PATCH] =?UTF-8?q?fix(client):=20=E3=83=AD=E3=83=BC=E3=82=AB?= =?UTF-8?q?=E3=83=AA=E3=82=BC=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=99=82=E3=81=AB=E3=83=AA=E3=83=AD=E3=83=BC=E3=83=89?= =?UTF-8?q?=E3=81=8C=E7=B9=B0=E3=82=8A=E8=BF=94=E3=81=95=E3=82=8C=E3=82=8B?= =?UTF-8?q?=E3=81=93=E3=81=A8=E3=81=8C=E3=81=82=E3=82=8B=E3=81=AE=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/frontend/src/config.ts | 6 +++++- packages/frontend/src/i18n.ts | 4 ++++ packages/frontend/src/init.ts | 11 +++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/frontend/src/config.ts b/packages/frontend/src/config.ts index 4b084d365..073b21a0a 100644 --- a/packages/frontend/src/config.ts +++ b/packages/frontend/src/config.ts @@ -10,8 +10,12 @@ export const apiUrl = url + '/api'; export const wsUrl = url.replace('http://', 'ws://').replace('https://', 'wss://') + '/streaming'; export const lang = miLocalStorage.getItem('lang'); export const langs = _LANGS_; -export const locale = JSON.parse(miLocalStorage.getItem('locale')); +export let locale = JSON.parse(miLocalStorage.getItem('locale')); export const version = _VERSION_; export const instanceName = siteName === 'Misskey' ? host : siteName; export const ui = miLocalStorage.getItem('ui'); export const debug = miLocalStorage.getItem('debug') === 'true'; + +export function updateLocale(newLocale) { + locale = newLocale; +} diff --git a/packages/frontend/src/i18n.ts b/packages/frontend/src/i18n.ts index 31e066960..220c6210c 100644 --- a/packages/frontend/src/i18n.ts +++ b/packages/frontend/src/i18n.ts @@ -3,3 +3,7 @@ import { locale } from '@/config'; import { I18n } from '@/scripts/i18n'; export const i18n = markRaw(new I18n(locale)); + +export function updateI18n(newLocale) { + i18n.ts = newLocale; +} diff --git a/packages/frontend/src/init.ts b/packages/frontend/src/init.ts index 079003ee8..36897545e 100644 --- a/packages/frontend/src/init.ts +++ b/packages/frontend/src/init.ts @@ -25,10 +25,10 @@ import JSON5 from 'json5'; import widgets from '@/widgets'; import directives from '@/directives'; import components from '@/components'; -import { version, ui, lang, host } from '@/config'; +import { version, ui, lang, host, updateLocale } from '@/config'; import { applyTheme } from '@/scripts/theme'; import { isDeviceDarkmode } from '@/scripts/is-device-darkmode'; -import { i18n } from '@/i18n'; +import { i18n, updateI18n } from '@/i18n'; import { confirm, alert, post, popup, toast } from '@/os'; import { stream } from '@/stream'; import * as sound from '@/scripts/sound'; @@ -87,9 +87,12 @@ import { fetchCustomEmojis } from './custom-emojis'; if (localeOutdated) { const res = await window.fetch(`/assets/locales/${lang}.${version}.json`); if (res.status === 200) { - miLocalStorage.setItem('locale', await res.text()); + const newLocale = await res.text(); + const parsedNewLocale = JSON.parse(newLocale); + miLocalStorage.setItem('locale', newLocale); miLocalStorage.setItem('localeVersion', version); - location.reload(); + updateLocale(parsedNewLocale); + updateI18n(parsedNewLocale); } } //#endregion