feat: pass useNetwork to translateToLocalByCSV

This commit is contained in:
bluelovers
2023-09-03 10:17:30 +08:00
parent 98621c1a83
commit 734b9deb68
2 changed files with 7 additions and 4 deletions

View File

@@ -1335,7 +1335,7 @@ export default {
}
if (tag.toLocal) {
// 翻译到本地语言
promises.push(this.translateToLocalByCSV(tag.value))
promises.push(this.translateToLocalByCSV(tag.value, void 0, void 0, useNetwork))
} else {
// 翻译到英文
promises.push(this.translateToEnByCSV(tag.value))

View File

@@ -161,7 +161,7 @@ export default {
})
})
},
async translateToLocalByCSV(text, tagCompleteFile = null, reload = false) {
async translateToLocalByCSV(text, tagCompleteFile = null, reload = false, useNetwork = false) {
let res = await this.getCSV(tagCompleteFile, reload)
text = text.trim().toLowerCase()
if (res.toLocal.has(text)) {
@@ -170,12 +170,15 @@ export default {
// 使用 , 分隔
const texts = text.split(',').map(t => t.trim())
let result = []
let needs = []
texts.forEach(t => {
if (res.toLocal.has(t)) {
result.push(res.toLocal.get(t))
} else if (useNetwork && t.length) {
needs.push(t)
}
})
if (result.length > 0) return result.join(', ')
if (result.length > 0 && (!needs.length || texts.length === result.length)) return result.join(', ')
}
return ''
},
@@ -215,4 +218,4 @@ export default {
return ''
},
}
}
}