两行 js 实现 html 全自动翻译。 无需改动页面、无语言配置文件、无 API Key、对 SEO 友好!
升级说明
- translate.service 深度绑定 GiteeAI 作为公有云翻译大模型算力支持
- translate.service 增加shell一键部署后通过访问自助完成GiteeAI的开通及整个接入流程。
- 增加 translate.ignore.setTextRegexs 可以正则的方式设置不进行翻译的文本 (有使用者wangliangyu提供)
- 增加 translate.lifecycle.execute.renderFinish 生命周期相关监控
- 增加 translate.visual.adjustTranslationSpacesByNodequeueUuid 用于进行视觉上的坐标处理,对类似于中译英场景,元素紧挨时两个单词会紧贴的问题。
- 增加 translate.visual 用于人眼看到的视觉层的处理
- 增加 translate.util.getElementPosition 用于计算实际显示的元素坐标及尺寸
- 优化 translate.reset() 只对最后一次的翻译进行还原操作(不刷新当前页面)
- 优化 translate.progress.api.startUITip() 翻译中的提示
- 优化for遍历对象时排除原型链上的属性
- 优化 init.json、language.json、ip.json、connectTest.json 为可配置,可屏蔽不发起网络请求
- 优化 translate.language.autoRecognitionLocalLanguage 自动识别当前语种时,识别的是 translate.setDocument() 区域的语种
- 优化对自定义接口路径时测速失败的支持
- 优化 translate.request.listener.start() 监听对旧浏览器的兼容
- 增加 PerformanceObserver 对象的判断,避免在老旧的浏览器里报错
- 增加对 translate.progress 的自动删除
- 优化翻译执行的等待,私有部署服务端可以禁用等待
- 增加 translate.office.fullExtract 以便对整站进行离线翻译的配置输出
- 优化 translate.util.textReplace 中翻英的阅读流畅度
- 去掉 translate.enterprise.isUse 的判断,更好适配定制精简版 translate.js
- 增加 translate.request.appendParams 的支持
- 增加 translate.listener.use 用于记录代码是否启用监听
- 增加对自定义翻译标签元素的忽略翻译能力支持
- 增加本地语种 希伯来语 的适配
- 优化 translate.changeLanguage 在iframe中进行切换时,也会影响父层一起切换语种
- translate.service 增加对内存缓存中的译文进行修改,可以模糊搜索原文,找到指定原文及译文,对翻译不满意的译文手动进行修改。
- translate.service 优化流量控制配置,如果cycleTime设置为0则是不使用流控
- translate.service 文本预处理,增加识别字符后的的特殊符号进行提取处理,不让特殊字符进入翻译的工具类
- translate.service 增加对内存缓存进行设置及清空相关管理接口
- translate.service 优化字符拆分跟 translate.js 的合并时空格补充的异常
- translate.service 优化中译英,分隔符本身也将全角转为半角的问题
- translate.service 全面优化文本分割能力,可通过配置自定义文本分割的字符
- translate.service 优化对 qwen3 大模型的支持及推理能力控制
- translate.service 增加 translate.service.set.useSemanticsModelApi 配置,可自由决定是否启用大模型判断语义
在线体验
http://res.zvo.cn/translate/demo.html
快速使用
在你的网页最末尾, </html>
之前,加入以下代码,会在页面的最底部出现选择语言的标签:
<script src="https://cdn.staticfile.net/translate.js/3.17.0/translate.js"></script> <script> //设置本地语种(当前网页的语种)。如果不设置,默认自动识别当前页面文字的语种。 可填写如 'english'、'chinese_simplified' 等
translate.language.setLocal('chinese_simplified'); translate.execute(); // 进行翻译 </script>
开源适配
如果您有开源项目,比如文档、cms、UI 框架、后台管理框架、等等,需要采用此进行多语言切换,欢迎喊我,传统 i18n 工作量太大,每次更新也容易遗漏,而 translate.js 是您最佳的选择,我们无偿提供全程接入讨论及遇到的问题跟随优化,希望我们的开源项目能互相产生作用一起越来越好。