diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2024-10-15 21:50:56 +0000 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2024-10-15 21:50:56 +0000 |
| commit | 68b90df00b2ea32a54d5de71a57b7d96d9767945 (patch) | |
| tree | 530ed2d8020b3774646b05ce83a27df90ce59995 /packages/frontend | |
| parent | merge: Improvements and tweaks to latest note handling (resolves #744) (!688) (diff) | |
| parent | fix import order in common.ts (diff) | |
| download | sharkey-68b90df00b2ea32a54d5de71a57b7d96d9767945.tar.gz sharkey-68b90df00b2ea32a54d5de71a57b7d96d9767945.tar.bz2 sharkey-68b90df00b2ea32a54d5de71a57b7d96d9767945.zip | |
merge: Refresh locales after any change, not just a version update (resolves #732) (!692)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/692
Closes #732
Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Marie <github@yuugi.dev>
Diffstat (limited to 'packages/frontend')
| -rw-r--r-- | packages/frontend/@types/global.d.ts | 1 | ||||
| -rw-r--r-- | packages/frontend/src/boot/common.ts | 9 | ||||
| -rw-r--r-- | packages/frontend/src/config.ts | 1 | ||||
| -rw-r--r-- | packages/frontend/vite.config.ts | 3 |
4 files changed, 9 insertions, 5 deletions
diff --git a/packages/frontend/@types/global.d.ts b/packages/frontend/@types/global.d.ts index 1025d1bedb..15373cbd2d 100644 --- a/packages/frontend/@types/global.d.ts +++ b/packages/frontend/@types/global.d.ts @@ -6,6 +6,7 @@ type FIXME = any; declare const _LANGS_: string[][]; +declare const _LANGS_VERSION_: string; declare const _VERSION_: string; declare const _ENV_: string; declare const _DEV_: boolean; diff --git a/packages/frontend/src/boot/common.ts b/packages/frontend/src/boot/common.ts index 94040c6413..f8ad123eca 100644 --- a/packages/frontend/src/boot/common.ts +++ b/packages/frontend/src/boot/common.ts @@ -8,7 +8,7 @@ import { compareVersions } from 'compare-versions'; import widgets from '@/widgets/index.js'; import directives from '@/directives/index.js'; import components from '@/components/index.js'; -import { version, lang, updateLocale, locale } from '@/config.js'; +import { version, lang, langsVersion, updateLocale, locale } from '@/config.js'; import { applyTheme } from '@/scripts/theme.js'; import { isDeviceDarkmode } from '@/scripts/is-device-darkmode.js'; import { updateI18n } from '@/i18n.js'; @@ -80,14 +80,15 @@ export async function common(createVue: () => App<Element>) { //#region Detect language & fetch translations const localeVersion = miLocalStorage.getItem('localeVersion'); - const localeOutdated = (localeVersion == null || localeVersion !== version || locale == null); + const localeOutdated = (localeVersion == null || localeVersion !== langsVersion || locale == null); if (localeOutdated) { - const res = await window.fetch(`/assets/locales/${lang}.${version}.json`); + console.info(`Updating locales from version ${localeVersion ?? 'N/A'} to ${langsVersion}`); + const res = await window.fetch(`/assets/locales/${lang}.${langsVersion}.json`); if (res.status === 200) { const newLocale = await res.text(); const parsedNewLocale = JSON.parse(newLocale); miLocalStorage.setItem('locale', newLocale); - miLocalStorage.setItem('localeVersion', version); + miLocalStorage.setItem('localeVersion', langsVersion); updateLocale(parsedNewLocale); updateI18n(parsedNewLocale); } diff --git a/packages/frontend/src/config.ts b/packages/frontend/src/config.ts index e3922a0cd5..0ad356b7ed 100644 --- a/packages/frontend/src/config.ts +++ b/packages/frontend/src/config.ts @@ -15,6 +15,7 @@ export const apiUrl = location.origin + '/api'; export const wsOrigin = location.origin; export const lang = miLocalStorage.getItem('lang') ?? 'en-US'; export const langs = _LANGS_; +export const langsVersion = _LANGS_VERSION_; const preParseLocale = miLocalStorage.getItem('locale'); export let locale = preParseLocale ? JSON.parse(preParseLocale) : null; export const version = _VERSION_; diff --git a/packages/frontend/vite.config.ts b/packages/frontend/vite.config.ts index 674fdbf680..513cb7e8bd 100644 --- a/packages/frontend/vite.config.ts +++ b/packages/frontend/vite.config.ts @@ -2,7 +2,7 @@ import path from 'path'; import pluginReplace from '@rollup/plugin-replace'; import pluginVue from '@vitejs/plugin-vue'; import { type UserConfig, defineConfig } from 'vite'; - +import { localesVersion } from '../../locales/version.js'; import locales from '../../locales/index.js'; import meta from '../../package.json'; import packageInfo from './package.json' with { type: 'json' }; @@ -110,6 +110,7 @@ export function getConfig(): UserConfig { define: { _VERSION_: JSON.stringify(meta.version), _LANGS_: JSON.stringify(Object.entries(locales).map(([k, v]) => [k, v._lang_])), + _LANGS_VERSION_: JSON.stringify(localesVersion), _ENV_: JSON.stringify(process.env.NODE_ENV), _DEV_: process.env.NODE_ENV !== 'production', _PERF_PREFIX_: JSON.stringify('Misskey:'), |