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