From 40dd443f4165befba5cb477aaa246532692ea32b Mon Sep 17 00:00:00 2001 From: syuilo <4439005+syuilo@users.noreply.github.com> Date: Tue, 20 Aug 2024 21:02:58 +0900 Subject: [PATCH] wip --- packages/backend/src/server/web/boot.js | 61 ++----------------------- packages/frontend/src/_dev_boot_.ts | 21 --------- packages/frontend/src/boot/common.ts | 21 ++------- packages/frontend/src/config.ts | 30 +++++++++--- packages/frontend/src/i18n.ts | 44 +++++++++++++++++- 5 files changed, 73 insertions(+), 104 deletions(-) diff --git a/packages/backend/src/server/web/boot.js b/packages/backend/src/server/web/boot.js index 4275dc9527..09b2475abb 100644 --- a/packages/backend/src/server/web/boot.js +++ b/packages/backend/src/server/web/boot.js @@ -33,59 +33,6 @@ return; } - //#region Detect language & fetch translations - if (!localStorage.hasOwnProperty('locale')) { - const supportedLangs = LANGS; - let lang = localStorage.getItem('lang'); - if (lang == null || !supportedLangs.includes(lang)) { - if (supportedLangs.includes(navigator.language)) { - lang = navigator.language; - } else { - lang = supportedLangs.find(x => x.split('-')[0] === navigator.language); - - // Fallback - if (lang == null) lang = 'en-US'; - } - } - - const metaRes = await window.fetch('/api/meta', { - method: 'POST', - body: JSON.stringify({}), - credentials: 'omit', - cache: 'no-cache', - headers: { - 'Content-Type': 'application/json', - }, - }); - if (metaRes.status !== 200) { - renderError('META_FETCH'); - return; - } - const meta = await metaRes.json(); - const v = meta.version; - if (v == null) { - renderError('META_FETCH_V'); - return; - } - - // for https://github.com/misskey-dev/misskey/issues/10202 - if (lang == null || lang.toString == null || lang.toString() === 'null') { - console.error('invalid lang value detected!!!', typeof lang, lang); - lang = 'en-US'; - } - - const localRes = await window.fetch(`/assets/locales/${lang}.${v}.json`); - if (localRes.status === 200) { - localStorage.setItem('lang', lang); - localStorage.setItem('locale', await localRes.text()); - localStorage.setItem('localeVersion', v); - } else { - renderError('LOCALE_FETCH'); - return; - } - } - //#endregion - //#region Script async function importAppScript() { await import(`/vite/${CLIENT_ENTRY}`) @@ -176,10 +123,10 @@
The following actions may solve the problem. / 以下を行うと解決する可能性があります。
-Clear the browser cache / ブラウザのキャッシュをクリアする
Update your os and browser / ブラウザおよびOSを最新バージョンに更新する
Disable an adblocker / アドブロッカーを無効にする
-(Tor Browser) Set dom.webaudio.enabled to true / dom.webaudio.enabledをtrueに設定する
+Clear the browser cache / ブラウザのキャッシュをクリアする
+(Tor Browser) Set dom.webaudio.enabled to true / dom.webaudio.enabledをtrueに設定する
ERROR CODE: ${code}
${JSON.stringify(details)}
`;
+ ${details.toString()} ${JSON.stringify(details)}
`;
errorsElement.appendChild(detailsElement);
addStyle(`
* {
@@ -320,6 +267,6 @@
#errorInfo {
width: 50%;
}
- }`)
+ }`);
}
})();
diff --git a/packages/frontend/src/_dev_boot_.ts b/packages/frontend/src/_dev_boot_.ts
index 7c6e537fbc..a43ee6d23f 100644
--- a/packages/frontend/src/_dev_boot_.ts
+++ b/packages/frontend/src/_dev_boot_.ts
@@ -23,27 +23,6 @@ async function main() {
//#region Detect language & fetch translations
- // dev-modeの場合は常に取り直す
- const supportedLangs = _LANGS_.map(it => it[0]);
- let lang: string | null | undefined = localStorage.getItem('lang');
- if (lang == null || !supportedLangs.includes(lang)) {
- if (supportedLangs.includes(navigator.language)) {
- lang = navigator.language;
- } else {
- lang = supportedLangs.find(x => x.split('-')[0] === navigator.language);
-
- // Fallback
- if (lang == null) lang = 'en-US';
- }
- }
-
- // TODO:今のままだと言語ファイル変更後はpnpm devをリスタートする必要があるので、chokidarを使ったり等で対応できるようにする
- const locale = _LANGS_FULL_.find(it => it[0] === lang);
- localStorage.setItem('lang', lang);
- localStorage.setItem('locale', JSON.stringify(locale[1]));
- localStorage.setItem('localeVersion', _VERSION_);
- //#endregion
-
//#region Theme
const theme = localStorage.getItem('theme');
if (theme) {
diff --git a/packages/frontend/src/boot/common.ts b/packages/frontend/src/boot/common.ts
index d86ae18ffe..605ea8ef3f 100644
--- a/packages/frontend/src/boot/common.ts
+++ b/packages/frontend/src/boot/common.ts
@@ -8,10 +8,10 @@ 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 } from '@/config.js';
import { applyTheme } from '@/scripts/theme.js';
import { isDeviceDarkmode } from '@/scripts/is-device-darkmode.js';
-import { updateI18n } from '@/i18n.js';
+import { locale, updateI18n, updateLocale } from '@/i18n.js';
import { $i, refreshAccount, login } from '@/account.js';
import { defaultStore, ColdDeviceStorage } from '@/store.js';
import { fetchInstance, instance } from '@/instance.js';
@@ -78,22 +78,6 @@ export async function common(createVue: () => App