refactor(client): i18n.locale -> i18n.ts

This commit is contained in:
syuilo
2022-01-28 11:39:49 +09:00
parent 6ebab5f577
commit 57ec04d9ec
74 changed files with 424 additions and 424 deletions

View File

@ -1,8 +1,8 @@
export class I18n<T extends Record<string, any>> {
public locale: T;
public ts: T;
constructor(locale: T) {
this.locale = locale;
this.ts = locale;
//#region BIND
this.t = this.t.bind(this);
@ -11,9 +11,9 @@ export class I18n<T extends Record<string, any>> {
// string にしているのは、ドット区切りでのパス指定を許可するため
// なるべくこのメソッド使うよりもlocale直接参照の方がvueのキャッシュ効いてパフォーマンスが良いかも
public t(key: string, args?: Record<string, any>): string {
public t(key: string, args?: Record<string, string>): string {
try {
let str = key.split('.').reduce((o, i) => o[i], this.locale) as string;
let str = key.split('.').reduce((o, i) => o[i], this.ts) as unknown as string;
if (args) {
for (const [k, v] of Object.entries(args)) {
@ -21,7 +21,7 @@ export class I18n<T extends Record<string, any>> {
}
}
return str;
} catch (e) {
} catch (err) {
console.warn(`missing localization '${key}'`);
return key;
}