🐛 Fix cannot translate fields with variables.

This commit is contained in:
zuiidea
2018-11-14 22:44:46 +08:00
parent d71c29ee2e
commit 6742207c77
+15 -3
View File
@@ -56,9 +56,21 @@ const transform = async ({ from, to, locales, outputPath }) => {
let res = key
let way = 'youdao'
if (key.indexOf('/') !== 0) {
res = await youdao({
q: key,
})
const reg = '{([^{}]*)}'
const tasks = key
.match(new RegExp(`${reg}|((?<=(${reg}|^)).*?(?=(${reg}|$)))`, 'g'))
.map(item => {
if (new RegExp(reg).test(item)) {
return Promise.resolve(item)
}
return youdao({
q: item,
from,
to,
})
})
res = (await Promise.all(tasks)).join('')
} else {
res = `/${to + key}`
way = 'link'