Skip to content

Commit d3201bc

Browse files
committed
feat: annotation fallback
1 parent 85699c2 commit d3201bc

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/editor/annotation.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,25 @@ const annotation: ExtensionModule = (ctx) => {
3030
const index = match.index
3131
const matchKey = match[0]
3232
const key = matchKey.replace(new RegExp(KEY_REG), '$1')
33+
let missing = false
3334

34-
const text = Global.loader.getValueByKey(key)
35+
let text = Global.loader.getValueByKey(key)
36+
// fallback to source
37+
if (!text && Global.displayLanguage !== Global.sourceLanguage) {
38+
text = Global.loader.getValueByKey(key, Global.sourceLanguage)
39+
missing = true
40+
}
41+
// no value on both displaying and source
42+
if (!text) {
43+
text = '⚠'
44+
missing = true
45+
}
3546

3647
const end = index + match[0].length - 1
3748
const start = end - match[1].length
49+
const color = missing
50+
? 'rgba(153, 153, 153, .3)'
51+
: 'rgba(153, 153, 153, .7)'
3852

3953
annotations.push({
4054
range: new Range(
@@ -43,7 +57,7 @@ const annotation: ExtensionModule = (ctx) => {
4357
),
4458
renderOptions: {
4559
after: {
46-
color: 'rgba(153, 153, 153, .7)',
60+
color,
4761
contentText: `◽️${text || '""'}`,
4862
fontWeight: 'normal',
4963
fontStyle: 'normal',

test/fixture/basic/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
"hour12": true
3232
}
3333
}
34-
}
34+
}

0 commit comments

Comments
 (0)