summaryrefslogtreecommitdiff
path: root/packages/sw/src/scripts/i18n.ts
diff options
context:
space:
mode:
authorzyoshoka <107108195+zyoshoka@users.noreply.github.com>2024-08-30 10:58:11 +0900
committerGitHub <noreply@github.com>2024-08-30 10:58:11 +0900
commit06855f769f1fe8c84fc3bbef615dac0a9fd2cf7b (patch)
tree5d69a21575f1ab993c79ad35f66186f8df7c7d89 /packages/sw/src/scripts/i18n.ts
parentfix(backend): correct `app`-type notification schema (#14471) (diff)
downloadmisskey-06855f769f1fe8c84fc3bbef615dac0a9fd2cf7b.tar.gz
misskey-06855f769f1fe8c84fc3bbef615dac0a9fd2cf7b.tar.bz2
misskey-06855f769f1fe8c84fc3bbef615dac0a9fd2cf7b.zip
refactor(sw): use fully typed locales (#14470)
* refactor(sw): use fully typed locales * fix(backend): enumerate achievement notification type
Diffstat (limited to 'packages/sw/src/scripts/i18n.ts')
-rw-r--r--packages/sw/src/scripts/i18n.ts37
1 files changed, 0 insertions, 37 deletions
diff --git a/packages/sw/src/scripts/i18n.ts b/packages/sw/src/scripts/i18n.ts
deleted file mode 100644
index 77b955dbe8..0000000000
--- a/packages/sw/src/scripts/i18n.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * SPDX-FileCopyrightText: syuilo and misskey-project
- * SPDX-License-Identifier: AGPL-3.0-only
- */
-
-export type Locale = { [key: string]: string | Locale };
-
-export class I18n<T extends Locale = Locale> {
- public ts: T;
-
- constructor(locale: T) {
- this.ts = locale;
-
- //#region BIND
- this.t = this.t.bind(this);
- //#endregion
- }
-
- // string にしているのは、ドット区切りでのパス指定を許可するため
- // なるべくこのメソッド使うよりもlocale直接参照の方がvueのキャッシュ効いてパフォーマンスが良いかも
- public t(key: string, args?: Record<string, string>): string {
- try {
- let str = key.split('.').reduce<Locale | Locale[keyof Locale]>((o, i) => o[i], this.ts);
- if (typeof str !== 'string') throw new Error();
-
- if (args) {
- for (const [k, v] of Object.entries(args)) {
- str = str.replace(`{${k}}`, v);
- }
- }
- return str;
- } catch (err) {
- console.warn(`missing localization '${key}'`);
- return key;
- }
- }
-}