提交 5ff64b0f authored 作者: 王鹏飞's avatar 王鹏飞

chore: 新增AI翻译

上级 48334617
// Extend menu
class AITranslate {
import BaseModalMenu from './common/BaseModalMenu'
import AIModal from './common/AIModal'
class AITranslate extends BaseModalMenu {
constructor() {
super()
this.title = '翻译'
this.iconSvg = `<svg fill="#000000" viewBox="0 0 32 32" id="icon" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><defs><style>.cls-1{fill:none;}</style></defs><title>translate</title><path d="M27.85,29H30L24,14H21.65l-6,15H17.8l1.6-4h6.85ZM20.2,23l2.62-6.56L25.45,23Z"></path><path d="M18,7V5H11V2H9V5H2V7H12.74a14.71,14.71,0,0,1-3.19,6.18A13.5,13.5,0,0,1,7.26,9H5.16a16.47,16.47,0,0,0,3,5.58A16.84,16.84,0,0,1,3,18l.75,1.86A18.47,18.47,0,0,0,9.53,16a16.92,16.92,0,0,0,5.76,3.84L16,18a14.48,14.48,0,0,1-5.12-3.37A17.64,17.64,0,0,0,14.8,7Z"></path><rect id="_Transparent_Rectangle_" data-name="<Transparent Rectangle>" class="cls-1" width="32" height="32"></rect></g></svg>`
this.tag = 'button'
}
getValue() {
return 'hello, 音频'
}
isActive() {
return false
}
isDisabled() {
return true
}
exec() {
return
getValue(editor) {
return <AIModal key={Date.now()} editor={editor} docAction="translate"></AIModal>
}
}
......
......@@ -28,6 +28,13 @@ const actionMap = {
(2)纠正敏感词或错别字之后正确的句子:
(3)更新之后的完整内容:
具体要校对的内容如下:`
},
translate: {
name: '翻译',
prompt: `请将以下文本翻译成英文。具体要求如下:
1、请确保翻译准确、流畅,并尽量保留原文的语义和风格。
2、翻译之后的文本以“翻译结果:”作为开头
待翻译文本:`
}
}
......@@ -79,6 +86,13 @@ export default function AIModal({ editor, docAction }) {
result = match[1].trim()
}
}
// 翻译结果判断
if (docAction === 'translate') {
const match = result.match(/翻译结果[::]?\s?([\s\S]*)/)
if (match) {
result = match[1].trim()
}
}
console.log(result)
editor.restoreSelection()
// 删除当前选中的节点
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论