feat:增加中英文转换util
This commit is contained in:
parent
4c8c1a355c
commit
f3f31e5b5c
32
openRenamerBackend/entity/bo/rules/TranslateRole.ts
Normal file
32
openRenamerBackend/entity/bo/rules/TranslateRole.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import RuleInterface from "./RuleInterface";
|
||||||
|
import FileObj from "../../vo/FileObj";
|
||||||
|
import * as TranslateUtil from "../../../util/TranslateUtil";
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
|
||||||
|
export default class TranslateRole implements RuleInterface {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1:简体转繁体 2:繁体转简体
|
||||||
|
*/
|
||||||
|
type: number;
|
||||||
|
/**
|
||||||
|
* 0、繁体中文,1、港澳繁体,2、台湾正体
|
||||||
|
*/
|
||||||
|
traditionalType: number;
|
||||||
|
|
||||||
|
constructor(data: any) {
|
||||||
|
this.type = data.type;
|
||||||
|
this.traditionalType = data.traditionalType;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
deal(file: FileObj): void {
|
||||||
|
if (this.type == 1) {
|
||||||
|
file.realName = TranslateUtil.toTraditionalChinese(file.realName, this.traditionalType);
|
||||||
|
} else if (this.type == 2) {
|
||||||
|
file.realName = TranslateUtil.toSimplifiedChinese(file.realName, this.traditionalType);
|
||||||
|
}
|
||||||
|
file.name = file.realName + file.expandName;
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ import InsertRule from "../bo/rules/InsertRule";
|
|||||||
import SerializationRule from "../bo/rules/SerializationRule";
|
import SerializationRule from "../bo/rules/SerializationRule";
|
||||||
import AutoRule from "../bo/rules/AutoRule";
|
import AutoRule from "../bo/rules/AutoRule";
|
||||||
import ReplaceRule from "../bo/rules/ReplaceRule";
|
import ReplaceRule from "../bo/rules/ReplaceRule";
|
||||||
|
import TranslateRole from "../bo/rules/TranslateRole";
|
||||||
|
|
||||||
export default class RuleObj {
|
export default class RuleObj {
|
||||||
type: string;
|
type: string;
|
||||||
@ -31,9 +32,11 @@ export default class RuleObj {
|
|||||||
case "replace":
|
case "replace":
|
||||||
this.data = new ReplaceRule(data.data);
|
this.data = new ReplaceRule(data.data);
|
||||||
break;
|
break;
|
||||||
|
case "translate":
|
||||||
|
this.data = new TranslateRole(data.data);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error("不支持的规则:" + this.type);
|
throw new Error("不支持的规则:" + this.type);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -233,7 +233,7 @@ var hk2tSearch = null;// WordsSearch
|
|||||||
* @param {any} text 原文本
|
* @param {any} text 原文本
|
||||||
* @param {any} type 0、繁体中文,1、港澳繁体,2、台湾正体
|
* @param {any} type 0、繁体中文,1、港澳繁体,2、台湾正体
|
||||||
*/
|
*/
|
||||||
export function ToTraditionalChinese(text: any, type: any) {
|
export function toTraditionalChinese(text: any, type: any) {
|
||||||
if (type == undefined) {
|
if (type == undefined) {
|
||||||
type = 0;
|
type = 0;
|
||||||
}
|
}
|
||||||
@ -255,7 +255,7 @@ export function ToTraditionalChinese(text: any, type: any) {
|
|||||||
* @param {any} text 原文本
|
* @param {any} text 原文本
|
||||||
* @param {any} srcType 0、繁体中文,1、港澳繁体,2、台湾正体
|
* @param {any} srcType 0、繁体中文,1、港澳繁体,2、台湾正体
|
||||||
*/
|
*/
|
||||||
export function ToSimplifiedChinese(text: string, srcType: any) {
|
export function toSimplifiedChinese(text: string, srcType: any) {
|
||||||
if (srcType == undefined) {
|
if (srcType == undefined) {
|
||||||
srcType = 0;
|
srcType = 0;
|
||||||
}
|
}
|
||||||
|
1878
openRenamerFront/pnpm-lock.yaml
generated
1878
openRenamerFront/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -6,6 +6,7 @@
|
|||||||
<el-menu-item :disabled="editRule != null" index="replace">替换</el-menu-item>
|
<el-menu-item :disabled="editRule != null" index="replace">替换</el-menu-item>
|
||||||
<el-menu-item :disabled="editRule != null || isAutoPlan" index="serialization">序列化</el-menu-item>
|
<el-menu-item :disabled="editRule != null || isAutoPlan" index="serialization">序列化</el-menu-item>
|
||||||
<el-menu-item :disabled="editRule != null" index="auto">自动识别</el-menu-item>
|
<el-menu-item :disabled="editRule != null" index="auto">自动识别</el-menu-item>
|
||||||
|
<el-menu-item :disabled="editRule != null" index="translate">简繁转换</el-menu-item>
|
||||||
</el-menu>
|
</el-menu>
|
||||||
<div class="rule">
|
<div class="rule">
|
||||||
<insert-rule ref="rule" :editRule="editRule" v-if="currentIndex === 'insert'"/>
|
<insert-rule ref="rule" :editRule="editRule" v-if="currentIndex === 'insert'"/>
|
||||||
@ -13,6 +14,7 @@
|
|||||||
<replace-rule ref="rule" :editRule="editRule" v-else-if="currentIndex === 'replace'"/>
|
<replace-rule ref="rule" :editRule="editRule" v-else-if="currentIndex === 'replace'"/>
|
||||||
<serialization-rule ref="rule" :editRule="editRule" v-else-if="currentIndex === 'serialization'"/>
|
<serialization-rule ref="rule" :editRule="editRule" v-else-if="currentIndex === 'serialization'"/>
|
||||||
<auto-rule ref="rule" :editRule="editRule" v-else-if="currentIndex === 'auto'"/>
|
<auto-rule ref="rule" :editRule="editRule" v-else-if="currentIndex === 'auto'"/>
|
||||||
|
<translate-rule ref="rule" :editRule="editRule" v-else-if="currentIndex === 'translate'"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="text-align: center">
|
<div style="text-align: center">
|
||||||
@ -26,9 +28,10 @@ import DeleteRule from "./rules/DeleteRule.vue";
|
|||||||
import SerializationRule from "./rules/SerializationRule.vue";
|
import SerializationRule from "./rules/SerializationRule.vue";
|
||||||
import AutoRule from "./rules/AutoRule";
|
import AutoRule from "./rules/AutoRule";
|
||||||
import ReplaceRule from "@/components/rules/ReplaceRule";
|
import ReplaceRule from "@/components/rules/ReplaceRule";
|
||||||
|
import TranslateRule from '@/components/rules/TranslateRule.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {InsertRule, DeleteRule, SerializationRule, AutoRule, ReplaceRule},
|
components: {InsertRule, DeleteRule, SerializationRule, AutoRule, ReplaceRule, TranslateRule},
|
||||||
props: ["editRule", "isAutoPlan"],
|
props: ["editRule", "isAutoPlan"],
|
||||||
emits: ["ruleAdd"],
|
emits: ["ruleAdd"],
|
||||||
name: "Rule",
|
name: "Rule",
|
||||||
|
77
openRenamerFront/src/components/rules/TranslateRule.vue
Normal file
77
openRenamerFront/src/components/rules/TranslateRule.vue
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<template>
|
||||||
|
<div class="flex">
|
||||||
|
<span class="left">操作:</span>
|
||||||
|
<div class="location">
|
||||||
|
<el-radio v-model="ruleObj.data.type" :label="1">简体转繁体</el-radio>
|
||||||
|
<el-radio v-model="ruleObj.data.type" :label="2">繁体转简体</el-radio>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex">
|
||||||
|
<span class="left">繁体类型:</span>
|
||||||
|
<div class="location">
|
||||||
|
<el-radio v-model="ruleObj.data.traditionalType" :label="0">繁体中文</el-radio>
|
||||||
|
<el-radio v-model="ruleObj.data.traditionalType" :label="1">港澳繁体</el-radio>
|
||||||
|
<el-radio v-model="ruleObj.data.traditionalType" :label="2">台湾正体</el-radio>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import {InfoFilled} from "@element-plus/icons-vue";
|
||||||
|
|
||||||
|
const traTypeMap = {
|
||||||
|
"0": "繁体中文",
|
||||||
|
"1": "港澳繁体",
|
||||||
|
"2": "台湾正体"
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "InsertRule",
|
||||||
|
props: ["editRule"],
|
||||||
|
components: {InfoFilled},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
ruleObj: {
|
||||||
|
type: "translate",
|
||||||
|
message: "",
|
||||||
|
data: {
|
||||||
|
type: 1,
|
||||||
|
traditionalType: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
if (this.editRule) {
|
||||||
|
console.log(this.editRule);
|
||||||
|
this.ruleObj = JSON.parse(JSON.stringify(this.editRule));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
exportObj() {
|
||||||
|
this.ruleObj.message = `简繁转换:"${this.ruleObj.data.type === 1 ? '简体转繁体' : '繁体转简体'}",繁体类型:${traTypeMap[this.ruleObj.data.traditionalType]}`;
|
||||||
|
return this.ruleObj;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
.flex {
|
||||||
|
display: flex;
|
||||||
|
justify-content: left;
|
||||||
|
align-items: center;
|
||||||
|
padding-top: 1em;
|
||||||
|
|
||||||
|
.left {
|
||||||
|
width: 6em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.location {
|
||||||
|
justify-content: left;
|
||||||
|
//flex-direction: column;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
@ -14,7 +14,7 @@ import router from '../router/index';
|
|||||||
async function request(url, method, params, body, isForm) {
|
async function request(url, method, params, body, isForm) {
|
||||||
let options = {
|
let options = {
|
||||||
url,
|
url,
|
||||||
baseURL: window.baseUrl + '/openRenamer/api',
|
baseURL: '/openRenamer/api',
|
||||||
method,
|
method,
|
||||||
params,
|
params,
|
||||||
headers: {token: window.token}
|
headers: {token: window.token}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user