feat: 支援無視 cjk 漢字將輸入內容轉英文

This commit is contained in:
bluelovers
2023-09-03 14:39:15 +08:00
parent 88345b644c
commit 0142815fba
3 changed files with 18 additions and 8 deletions

View File

@@ -8,6 +8,7 @@
"preview": "vite preview"
},
"dependencies": {
"@lazy-cjk/zh-slugify": "^1.0.86",
"autosize-input": "^1.0.2",
"axios": "^1.4.0",
"js-yaml": "^4.1.0",

View File

@@ -151,6 +151,7 @@ import globals from "../globals";
import jsYaml from "js-yaml";
import {ref} from "vue";
import Hotkey from "@/components/hotkey.vue";
import { slugify } from '@lazy-cjk/zh-slugify';
export default {
name: 'App',
@@ -806,7 +807,10 @@ export default {
data.toLocal.set(t, [local])
}
})
const key = slugify(local, true)
!data.toEn.has(key) && data.toEn.set(key, en)
data.toEn.set(local, en)
// console.log('setData:groupTags', local, key, en)
}
this.groupTags.forEach((item, index) => {
item.tabKey = 'groupTags-' + index

View File

@@ -1,6 +1,7 @@
import common from "@/utils/common"
import Papa from 'papaparse'
import globals from "../../globals";
import { slugify } from '@lazy-cjk/zh-slugify';
export default {
props: {
@@ -100,7 +101,10 @@ export default {
en.replace(/\-/g, ' '),
]
texts.forEach(t => data.toLocal.set(t, local))
const key = slugify(local, true)
!data.toEn.has(key) && data.toEn.set(key, en)
data.toEn.set(local, en)
// console.log('setData:csv', local, key, en)
}
if (!tagCompleteFile) {
@@ -181,11 +185,7 @@ export default {
},
async translateToEnByCSV(text, tagCompleteFile = null, reload = false) {
let res = await this.getCSV(tagCompleteFile, reload)
text = text.trim().toLowerCase()
if (res.toEn.has(text)) {
return res.toEn.get(text)
}
return ''
return this._toEn(text, res.toEn)
},
async translateToLocalByGroupTags(text) {
console.log(text)
@@ -208,11 +208,16 @@ export default {
return ''
},
async translateToEnByGroupTags(text) {
return this._toEn(text, this.groupTagsTranslateCache.toEn)
},
_toEn(text, toEn) {
text = text.trim().toLowerCase()
if (this.groupTagsTranslateCache.toEn.has(text)) {
return this.groupTagsTranslateCache.toEn.get(text)
if (toEn.has(text)) {
return toEn.get(text)
} else if ((text = slugify(text, true)) && toEn.has(text)) {
return toEn.get(text)
}
return ''
},
}
}
}