Skip to content

Commit 6742207

Browse files
committed
🐛 Fix cannot translate fields with variables.
1 parent d71c29e commit 6742207

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

scripts/translate.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,21 @@ const transform = async ({ from, to, locales, outputPath }) => {
5656
let res = key
5757
let way = 'youdao'
5858
if (key.indexOf('/') !== 0) {
59-
res = await youdao({
60-
q: key,
61-
})
59+
const reg = '{([^{}]*)}'
60+
const tasks = key
61+
.match(new RegExp(`${reg}|((?<=(${reg}|^)).*?(?=(${reg}|$)))`, 'g'))
62+
.map(item => {
63+
if (new RegExp(reg).test(item)) {
64+
return Promise.resolve(item)
65+
}
66+
return youdao({
67+
q: item,
68+
from,
69+
to,
70+
})
71+
})
72+
73+
res = (await Promise.all(tasks)).join('')
6274
} else {
6375
res = `/${to + key}`
6476
way = 'link'

0 commit comments

Comments
 (0)