mirror of
https://github.com/Physton/sd-webui-prompt-all-in-one.git
synced 2026-05-01 03:31:41 +00:00
refactor: _translateToLocalBy
This commit is contained in:
@@ -161,19 +161,19 @@ export default {
|
||||
})
|
||||
})
|
||||
},
|
||||
async translateToLocalByCSV(text, tagCompleteFile = null, reload = false, useNetwork = false) {
|
||||
let res = await this.getCSV(tagCompleteFile, reload)
|
||||
_translateToLocalBy(text, toLocal, useNetwork = false) {
|
||||
text = text.trim().toLowerCase()
|
||||
if (res.toLocal.has(text)) {
|
||||
return res.toLocal.get(text)
|
||||
let _localToString = value => (value.join?.(' / ') ?? value)
|
||||
if (toLocal.has(text)) {
|
||||
return _localToString(toLocal.get(text))
|
||||
} else {
|
||||
// 使用 , 分隔
|
||||
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))
|
||||
if (toLocal.has(t)) {
|
||||
result.push(_localToString(toLocal.get(t)))
|
||||
} else if (useNetwork && t.length) {
|
||||
needs.push(t)
|
||||
}
|
||||
@@ -182,6 +182,10 @@ export default {
|
||||
}
|
||||
return ''
|
||||
},
|
||||
async translateToLocalByCSV(text, tagCompleteFile = null, reload = false, useNetwork = false) {
|
||||
let res = await this.getCSV(tagCompleteFile, reload)
|
||||
return this._translateToLocalBy(text, res.toLocal, useNetwork)
|
||||
},
|
||||
async translateToEnByCSV(text, tagCompleteFile = null, reload = false) {
|
||||
let res = await this.getCSV(tagCompleteFile, reload)
|
||||
text = text.trim().toLowerCase()
|
||||
@@ -192,26 +196,7 @@ export default {
|
||||
},
|
||||
async translateToLocalByGroupTags(text, useNetwork = false) {
|
||||
console.log('translateToLocalByGroupTags', text)
|
||||
text = text.trim().toLowerCase()
|
||||
if (this.groupTagsTranslateCache.toLocal.has(text)) {
|
||||
let value = this.groupTagsTranslateCache.toLocal.get(text)
|
||||
return value.join(' / ')
|
||||
} else {
|
||||
// 使用 , 分隔
|
||||
const texts = text.split(',').map(t => t.trim())
|
||||
let result = []
|
||||
let needs = []
|
||||
texts.forEach(t => {
|
||||
if (this.groupTagsTranslateCache.toLocal.has(t)) {
|
||||
let value = this.groupTagsTranslateCache.toLocal.get(t)
|
||||
result.push(value.join(' / '))
|
||||
} else if (useNetwork && t.length) {
|
||||
needs.push(t)
|
||||
}
|
||||
})
|
||||
if (result.length > 0 && !needs.length) return result.join(', ')
|
||||
}
|
||||
return ''
|
||||
return this._translateToLocalBy(text, this.groupTagsTranslateCache.toLocal, useNetwork)
|
||||
},
|
||||
async translateToEnByGroupTags(text) {
|
||||
text = text.trim().toLowerCase()
|
||||
|
||||
Reference in New Issue
Block a user