Skip to content

Commit aafc30b

Browse files
committed
update localization lookup function
1 parent d1be4d0 commit aafc30b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/util/intl.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,23 @@ class Intl {
1515
this.lang = lang
1616
}
1717
tl(key: string) {
18-
this.tokens.add(key)
19-
let v = this.dict[this.lang]?.[key] ? this.dict[this.lang][key] : key
20-
// if (v === key) debugger
21-
return v
18+
let segments = key.split('.')
19+
let dict = this.dict[this.lang]
20+
for (let i = 0; i < segments.length; i++) {
21+
if (dict[segments[i]]) {
22+
dict = dict[segments[i]]
23+
} else {
24+
this.tokens.add(key)
25+
return key
26+
}
27+
}
28+
return typeof dict === 'string' ? dict : key
2229
}
2330
register(name: string, dict: any) {
2431
this.dict[name] = dict
2532
}
2633
diff(showDefaultValues: boolean) {
34+
throw new Error('Not implemented')
2735
let root = this.dict.en
2836
let diff = []
2937
for (let lang in this.dict) {

0 commit comments

Comments
 (0)