summaryrefslogtreecommitdiff
path: root/packages/frontend-shared
diff options
context:
space:
mode:
authoranatawa12 <anatawa12@icloud.com>2025-08-08 11:26:18 +0900
committerGitHub <noreply@github.com>2025-08-08 11:26:18 +0900
commit8598f3912ecc16f9b7c3f502e09d9ea96f7e507d (patch)
tree73b24c7ab473189a679ae6aa476b6822f812cbed /packages/frontend-shared
parentUpdate CONTRIBUTING.md (diff)
downloadmisskey-8598f3912ecc16f9b7c3f502e09d9ea96f7e507d.tar.gz
misskey-8598f3912ecc16f9b7c3f502e09d9ea96f7e507d.tar.bz2
misskey-8598f3912ecc16f9b7c3f502e09d9ea96f7e507d.zip
per-locale bundle & inline locale (#16369)
* feat: split entry file by locale name * chore: とりあえず transform hook で雑に分割 * chore: とりあえず transform 結果をいい感じに * chore: concurrent buildで高速化 * chore: vite ではローケルのないものをビルドして後処理でどうにかするように * chore: 後処理のためにi18n.jを単体になるように切り出す * chore: use typescript * chore: remove unref(i18n) in vite build process * chore: inline variable * fix: build error * fix: i18n.ts.something.replaceAll() become error * chore: ignore export specifier from error * chore: support i18n.tsx as object * chore: process literal for all files * chore: split config and locale * chore: inline locale name * chore: remove updating locale in boot common * chore: use top-level await to load locales * chore: inline locale * chore: remove loading locale from boot.js * chore: remove loading locale from boot.js * コメント追加 * fix test; fetchに失敗する * import削除ログをdebugレベルに * fix: watch pug * chore: use hash for entry files * chore: remove es-module-lexer from dependencies * chore: move to frontend-builder * chore: use inline locale in embed * chore: refetch json on hot reload * feat: store localization related to boot.js in backend in bootloaderLocales localstorage * 応急処置を戻す * fix spex * fix `Using i18n identifier "e" directly. Skipping inlining.` warning * refactor: use scriptsDir parameter * chore: remove i18n from depmap * chore: make build crash if errors * error -> warn few conditions * use inline object * update localstorage keys * remove accessing locale localstorage * fix: failed to process i18n.tsx.aaa({x:i18n.bbb})
Diffstat (limited to 'packages/frontend-shared')
-rw-r--r--packages/frontend-shared/js/config.ts8
-rw-r--r--packages/frontend-shared/js/i18n.ts6
-rw-r--r--packages/frontend-shared/js/locale.ts14
-rw-r--r--packages/frontend-shared/js/store-boot-errors.ts12
4 files changed, 27 insertions, 13 deletions
diff --git a/packages/frontend-shared/js/config.ts b/packages/frontend-shared/js/config.ts
index 4963d631f9..ac5c5629f3 100644
--- a/packages/frontend-shared/js/config.ts
+++ b/packages/frontend-shared/js/config.ts
@@ -3,8 +3,6 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
-import type { Locale } from '../../../locales/index.js';
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const address = new URL(document.querySelector<HTMLMetaElement>('meta[property="instance_url"]')?.content || location.href);
const siteName = document.querySelector<HTMLMetaElement>('meta[property="og:site_name"]')?.content;
@@ -17,14 +15,8 @@ export const apiUrl = location.origin + '/api';
export const wsOrigin = location.origin;
export const lang = localStorage.getItem('lang') ?? 'en-US';
export const langs = _LANGS_;
-const preParseLocale = localStorage.getItem('locale');
-export let locale: Locale = preParseLocale ? JSON.parse(preParseLocale) : null;
export const version = _VERSION_;
export const instanceName = (siteName === 'Misskey' || siteName == null) ? host : siteName;
export const ui = localStorage.getItem('ui');
export const debug = localStorage.getItem('debug') === 'true';
export const isSafeMode = localStorage.getItem('isSafeMode') === 'true';
-
-export function updateLocale(newLocale: Locale): void {
- locale = newLocale;
-}
diff --git a/packages/frontend-shared/js/i18n.ts b/packages/frontend-shared/js/i18n.ts
index 25581b969a..bd9ba0922a 100644
--- a/packages/frontend-shared/js/i18n.ts
+++ b/packages/frontend-shared/js/i18n.ts
@@ -39,11 +39,7 @@ export class I18n<T extends ILocale> {
private devMode: boolean;
constructor(public locale: T, devMode = false) {
- // 場合によってはバージョンアップ前の翻訳データを参照した結果存在しないプロパティにアクセスしてクライアントが起動できなくなることがある問題の応急処置として非devモードでもプロキシする
- // TODO: https://github.com/misskey-dev/misskey/issues/14453 が実装されたらそのようなことは発生し得なくなるため消す
- const oukyuusyoti = true;
-
- this.devMode = devMode || oukyuusyoti;
+ this.devMode = devMode;
//#region BIND
this.t = this.t.bind(this);
diff --git a/packages/frontend-shared/js/locale.ts b/packages/frontend-shared/js/locale.ts
new file mode 100644
index 0000000000..87e3922fd9
--- /dev/null
+++ b/packages/frontend-shared/js/locale.ts
@@ -0,0 +1,14 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and misskey-project
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import { lang, version } from '@@/js/config.js';
+import type { Locale } from '../../../locales/index.js';
+
+// ここはビルド時に const locale = JSON.parse("...") みたいな感じで置き換えられるので top-level await は消える
+export let locale: Locale = await window.fetch(`/assets/locales/${lang}.${version}.json`).then(r => r.json(), () => null);
+
+export function updateLocale(newLocale: Locale): void {
+ locale = newLocale;
+}
diff --git a/packages/frontend-shared/js/store-boot-errors.ts b/packages/frontend-shared/js/store-boot-errors.ts
new file mode 100644
index 0000000000..31e6248445
--- /dev/null
+++ b/packages/frontend-shared/js/store-boot-errors.ts
@@ -0,0 +1,12 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and misskey-project
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import type { Locale } from '../../../locales/index.js';
+
+type BootLoaderLocaleBody = Locale['_bootErrors'] & { reload: Locale['reload'] };
+
+export function storeBootloaderErrors(locale: BootLoaderLocaleBody) {
+ localStorage.setItem('bootloaderLocales', JSON.stringify(locale));
+}