summaryrefslogtreecommitdiff
path: root/src/misc
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2021-02-13 12:28:26 +0900
committersyuilo <syuilotan@yahoo.co.jp>2021-02-13 12:28:26 +0900
commitebadd7fd3f255af3dd5035afe1d0d75337fa39a4 (patch)
tree5a441d13c74092560b913b5eef4ff4252f128fd5 /src/misc
parentMerge pull request #7187 from syuilo/dependabot/npm_and_yarn/typescript-4.1.5 (diff)
downloadsharkey-ebadd7fd3f255af3dd5035afe1d0d75337fa39a4.tar.gz
sharkey-ebadd7fd3f255af3dd5035afe1d0d75337fa39a4.tar.bz2
sharkey-ebadd7fd3f255af3dd5035afe1d0d75337fa39a4.zip
wip: email notification
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/i18n.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/misc/i18n.ts b/src/misc/i18n.ts
new file mode 100644
index 0000000000..4fa398763a
--- /dev/null
+++ b/src/misc/i18n.ts
@@ -0,0 +1,29 @@
+export class I18n<T extends Record<string, any>> {
+ public locale: T;
+
+ constructor(locale: T) {
+ this.locale = locale;
+
+ //#region BIND
+ this.t = this.t.bind(this);
+ //#endregion
+ }
+
+ // string にしているのは、ドット区切りでのパス指定を許可するため
+ // なるべくこのメソッド使うよりもlocale直接参照の方がvueのキャッシュ効いてパフォーマンスが良いかも
+ public t(key: string, args?: Record<string, any>): string {
+ try {
+ let str = key.split('.').reduce((o, i) => o[i], this.locale) as string;
+
+ if (args) {
+ for (const [k, v] of Object.entries(args)) {
+ str = str.replace(`{${k}}`, v);
+ }
+ }
+ return str;
+ } catch (e) {
+ console.warn(`missing localization '${key}'`);
+ return key;
+ }
+ }
+}