Fixed 267U.pre2
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
export class I18n {
|
||||
locale;
|
||||
constructor(locale){
|
||||
this.locale = locale;
|
||||
//#region BIND
|
||||
this.t = this.t.bind(this);
|
||||
//#endregion
|
||||
}
|
||||
// string にしているのは、ドット区切りでのパス指定を許可するため
|
||||
// なるべくこのメソッド使うよりもlocale直接参照の方がvueのキャッシュ効いてパフォーマンスが良いかも
|
||||
t(key, args) {
|
||||
try {
|
||||
let str = key.split(".").reduce((o, i)=>o[i], this.locale);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user