i18n-jsautotranslate 3.12.0 → 3.12.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -18
- package/index.js +53 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ http://res.zvo.cn/translate/demo.html
|
|
|
57
57
|
在网页最末尾, ````</html>```` 之前,加入以下代码,一般在页面的最底部就出现了选择语言的 select 切换标签。 其实就这么简单:
|
|
58
58
|
|
|
59
59
|
````
|
|
60
|
-
<script src="https://cdn.staticfile.net/translate.js/3.
|
|
60
|
+
<script src="https://cdn.staticfile.net/translate.js/3.12.0/translate.js"></script>
|
|
61
61
|
<script>
|
|
62
62
|
translate.language.setLocal('chinese_simplified'); //设置本地语种(当前网页的语种)。如果不设置,默认自动识别当前网页显示文字的语种。 可填写如 'english'、'chinese_simplified' 等,具体参见文档下方关于此的说明。
|
|
63
63
|
translate.service.use('client.edge'); //设置机器翻译服务通道,直接客户端本身,不依赖服务端 。相关说明参考 http://translate.zvo.cn/43086.html
|
|
@@ -121,7 +121,7 @@ translate.execute();//进行翻译
|
|
|
121
121
|
</ul>
|
|
122
122
|
|
|
123
123
|
<!-- 引入多语言切换的js -->
|
|
124
|
-
<script src="https://cdn.staticfile.net/translate.js/3.
|
|
124
|
+
<script src="https://cdn.staticfile.net/translate.js/3.12.0/translate.js"></script>
|
|
125
125
|
<script>
|
|
126
126
|
translate.selectLanguageTag.show = false; //不出现的select的选择语言
|
|
127
127
|
translate.service.use('client.edge'); //设置机器翻译服务通道
|
|
@@ -152,27 +152,28 @@ translate.execute();//进行翻译
|
|
|
152
152
|
这里给出两个使用比较好的网站作为实际示例参考:
|
|
153
153
|
|
|
154
154
|
* [**RICE中国大米展**](https://www.cnrice.com.cn)
|
|
155
|
-
* [
|
|
156
|
-
* [**第十一届国际潮青联谊年会组委会**](https://ityc.org.cn)
|
|
155
|
+
* [**第十一届国际潮青联谊年会组委会**](http://ityc.org.cn)
|
|
157
156
|
|
|
158
157
|
另外,很多开源框架及产品也都已将此翻译能力接入了自身系统,赋予自身系统多语言切换能力。
|
|
159
158
|
|
|
160
159
|
|
|
161
160
|
## 这些开源产品已内置本功能
|
|
162
|
-
* [
|
|
163
|
-
* [
|
|
164
|
-
* [
|
|
165
|
-
* [
|
|
166
|
-
* [
|
|
167
|
-
* [
|
|
168
|
-
* [
|
|
169
|
-
* [
|
|
170
|
-
* [
|
|
171
|
-
* [
|
|
172
|
-
* [
|
|
173
|
-
* [
|
|
161
|
+
* [管伊佳ERP](https://gitee.com/jishenghua/JSH_ERP) 国产开源ERP系统关注度第一,专注进销存、生产、总账
|
|
162
|
+
* [FixIt](https://github.com/hugo-fixit/cmpt-translate) 一款简洁、优雅且先进的Hugo 博客主题
|
|
163
|
+
* [Z-Blog](https://app.zblogcn.com/?id=49226) 易用的博客程序,功能丰富,模板多样,助轻松搭建个性博客。
|
|
164
|
+
* [Discuz](https://addon.dismall.com/plugins/domi_translate.html) 知名论坛系统,功能强大,插件众多,打造活跃互动的网络社区。
|
|
165
|
+
* [Pear Admin Layui](https://gitee.com/pear-admin/Pear-Admin-Layui/tree/i18n/) Pear Admin Layui 是基于 Layui 的后台管理模板,简洁美观,实用高效。
|
|
166
|
+
* [kefu.js](https://gitee.com/mail_osc/kefu.js) 开源js聊天界面插件,方便快捷,助力网站沟通服务。
|
|
167
|
+
* [Layui](https://gitee.com/mail_osc/translate_layui) 简洁好用的前端框架,组件丰富,上手容易,广受开发者青睐。
|
|
168
|
+
* [wangmarket CMS](http://cms.zvo.cn) 开源的SAAS云建站系统,可私有部署,可通过后台任意开通多个网站,每个网站独立管理
|
|
169
|
+
* [易优CMS](https://www.eyoucms.com/mall/plus/29751.html) 功能强大的内容管理系统,操作简便,模板随心选。
|
|
170
|
+
* [迅睿CMS](https://www.xunruicms.com/shop/1285.html) 一款功能完善的内容管理系统,性能卓越,易于使用。
|
|
171
|
+
* [chanyue-cms](https://gitee.com/yanyutao0402/chanyue-cms) 基于Node、Express、MySQL、Vue3研发的高质量实用型CMS系统
|
|
172
|
+
* [phpok cms](https://gitee.com/phpok/phpok) 极其自由的企业站程序,支持各种自定义配置。
|
|
173
|
+
* [RPCMS](https://app.rpcms.cn/app/149.html) 轻量型php内容管理系统,小型、轻量,但功能丰富,可扩展性强。
|
|
174
|
+
* [Masuit.MyBlogs](https://gitee.com/masuit/Masuit.MyBlogs) 高性能高安全性低占用的个人博客系统
|
|
174
175
|
...
|
|
175
|
-
如果您有开源项目,比如文档、cms、UI
|
|
176
|
+
如果您有开源项目,比如文档、cms、UI 框架、后台管理框架、等等,需要采用此进行多语言切换,欢迎喊我,无偿提供全程接入讨论及遇到的问题跟随优化,希望我们的开源项目能互相产生作用一起越来越好。如果你的项目在这个列表中没有,欢迎联系我说明,我给加入进去
|
|
176
177
|
|
|
177
178
|
|
|
178
179
|
# 哪些能力
|
|
@@ -185,6 +186,15 @@ translate.execute();//进行翻译
|
|
|
185
186
|
翻译是基于您现有的网站内容,不需要重新建设多语种网站,只需要解析域名到您私有部署的服务器,就可以完成全站翻译。
|
|
186
187
|
详细参见 [TCDN](http://translate.zvo.cn/41159.html)
|
|
187
188
|
|
|
189
|
+
# TCDN部署
|
|
190
|
+
tcdn是translate.js 的高级版本,它的能力是让你原本的网站可以用不同的域名访问到不同的语种。而不同的语种,都可以被收录!它可以免费部署到服务器进行使用。注意,它需要使用个1核2G的服务器进行部署的。
|
|
191
|
+
部署方式有两种:
|
|
192
|
+
### 宝塔部署
|
|
193
|
+
首选需要你的宝塔面板需要 9.3.0 及以上版本。 不然你在下一步部署时,是搜索不到我们 TCDN 这个服务的。
|
|
194
|
+
如果你没有安装宝塔面板,可以先去安装宝塔面板: [https://www.bt.cn/new/download.html?r=dk_tcdn](https://www.bt.cn/new/download.html?r=dk_tcdn)
|
|
195
|
+
详细部署步骤可参考: [https://translate.zvo.cn/302663.html](https://translate.zvo.cn/302663.html)
|
|
196
|
+
### 服务器部署
|
|
197
|
+
需要一个干净的服务器,不依赖任何环境的情况下进行的部署,需要你懂点linux命令行, 部署方式参考: [https://translate.zvo.cn/236899.html](https://translate.zvo.cn/236899.html)
|
|
188
198
|
|
|
189
199
|
# 开源仓库目录结构
|
|
190
200
|
* **deploy** - 部署相关,比如shell文件、sql数据库文件等
|
|
@@ -216,7 +226,6 @@ translate.execute();//进行翻译
|
|
|
216
226
|
|
|
217
227
|
# 优秀开源项目及社区推荐
|
|
218
228
|
[Featbit](https://github.com/featbit/featbit) 一个100%开源的 Feature flags / Feature Management 平台工具
|
|
219
|
-
[LinkWeChat](https://gitee.com/LinkWeChat/link-wechat) LinkWeChat 是基于企业微信的开源 SCRM 系统,是企业私域流量管理与营销的综合解决方案。
|
|
220
229
|
[IoTSharp](https://gitee.com/IoTSharp) IoTSharp 是一个 基于.Net Core 开源的物联网基础平台, 支持 HTTP、MQTT 、CoAp 协议
|
|
221
230
|
[流之云](https://gitee.com/ntdgg) 信息化、数字化服务提供商
|
|
222
231
|
|
package/index.js
CHANGED
|
@@ -12,7 +12,7 @@ var translate = {
|
|
|
12
12
|
* 格式:major.minor.patch.date
|
|
13
13
|
*/
|
|
14
14
|
// AUTO_VERSION_START
|
|
15
|
-
version: '3.12.
|
|
15
|
+
version: '3.12.5.20250111',
|
|
16
16
|
// AUTO_VERSION_END
|
|
17
17
|
/*
|
|
18
18
|
当前使用的版本,默认使用v2. 可使用 setUseVersion2();
|
|
@@ -148,7 +148,12 @@ var translate = {
|
|
|
148
148
|
|
|
149
149
|
//判断translate 的id是否存在,不存在就创建一个
|
|
150
150
|
if(document.getElementById(translate.selectLanguageTag.documentId) == null){
|
|
151
|
-
var
|
|
151
|
+
var findBody = document.getElementsByTagName('body');
|
|
152
|
+
if(findBody.length == 0){
|
|
153
|
+
console.log('body tag not find, translate.selectLanguageTag.render() is not show Select Language');
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
var body_trans = findBody[0];
|
|
152
157
|
var div = document.createElement("div"); //创建一个script标签
|
|
153
158
|
div.id=translate.selectLanguageTag.documentId;
|
|
154
159
|
body_trans.appendChild(div);
|
|
@@ -1285,9 +1290,15 @@ var translate = {
|
|
|
1285
1290
|
|
|
1286
1291
|
//判断本地语种跟要翻译的目标语种是否一样,如果是一样,那就不需要进行任何翻译
|
|
1287
1292
|
if(translate.to == translate.language.getLocal()){
|
|
1288
|
-
|
|
1293
|
+
if(translate.language.translateLocal){
|
|
1294
|
+
//这是自定义设置的允许翻译本地语种中,跟本地语种不一致的语言进行翻译
|
|
1295
|
+
|
|
1296
|
+
}else{
|
|
1297
|
+
return;
|
|
1298
|
+
}
|
|
1289
1299
|
}
|
|
1290
1300
|
|
|
1301
|
+
|
|
1291
1302
|
/********** 翻译进行 */
|
|
1292
1303
|
|
|
1293
1304
|
//先进行图片的翻译替换,毕竟图片还有加载的过程
|
|
@@ -1939,12 +1950,15 @@ var translate = {
|
|
|
1939
1950
|
//替换渲染
|
|
1940
1951
|
if(typeof(originalText) != 'undefined' && originalText.length > 0){
|
|
1941
1952
|
if(typeof(node[attribute]) != 'undefined'){
|
|
1942
|
-
|
|
1953
|
+
//这种是主流框架,像是vue、element、react 都是用这种 DOM Property 的方式,更快
|
|
1943
1954
|
node[attribute] = node[attribute].replace(new RegExp(translate.util.regExp.pattern(originalText),'g'), translate.util.regExp.resultText(resultText));
|
|
1944
1955
|
}
|
|
1945
|
-
|
|
1956
|
+
|
|
1957
|
+
//这种 Html Attribute 方式 是 v3.12 版本之前一直使用的方式,速度上要慢于 上面的,为了向前兼容不至于升级出问题,后面可能会优化掉
|
|
1958
|
+
var htmlAttributeValue = node.getAttribute(attribute);
|
|
1959
|
+
if(htmlAttributeValue != null && typeof(htmlAttributeValue) != 'undefined'){
|
|
1946
1960
|
//这个才是在v3.9.2 后要用的,上面的留着只是为了适配以前的
|
|
1947
|
-
node.setAttribute(attribute,
|
|
1961
|
+
node.setAttribute(attribute, htmlAttributeValue.replace(new RegExp(translate.util.regExp.pattern(originalText),'g'), translate.util.regExp.resultText(resultText)));
|
|
1948
1962
|
}
|
|
1949
1963
|
}
|
|
1950
1964
|
return result;
|
|
@@ -2131,12 +2145,33 @@ var translate = {
|
|
|
2131
2145
|
for(var attributeName_index in translate.element.tagAttribute[nodeNameLowerCase]){
|
|
2132
2146
|
|
|
2133
2147
|
var attributeName = translate.element.tagAttribute[nodeNameLowerCase][attributeName_index];
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2148
|
+
//console.log(attributeName);
|
|
2149
|
+
//console.log(node.getAttribute(attributeName));
|
|
2150
|
+
|
|
2151
|
+
/*
|
|
2152
|
+
* 默认是 HtmlAtrribute 也就是 HTML特性。取值有两个:
|
|
2153
|
+
* HTMLAtrribute : HTML特性
|
|
2154
|
+
* DOMProperty : DOM属性
|
|
2155
|
+
*/
|
|
2156
|
+
var DOMPropOrHTMLAttr = 'HTMLAtrribute';
|
|
2157
|
+
var attributeValue = node.getAttribute(attributeName);
|
|
2158
|
+
if(typeof(attributeValue) == 'undefined' || attributeValue == null){
|
|
2159
|
+
//vue、element、react 中的一些动态赋值,比如 element 中的 el-select 选中后赋予显示出来的文本,getAttribute 就取不到,因为是改动的 DOM属性,所以要用这种方式才能取出来
|
|
2160
|
+
attributeValue = node[attributeName];
|
|
2161
|
+
DOMPropOrHTMLAttr = 'DOMProperty';
|
|
2162
|
+
}
|
|
2163
|
+
if(typeof(attributeValue) == 'undefined' || attributeValue == null){
|
|
2164
|
+
//这个tag标签没有这个属性,忽略
|
|
2165
|
+
continue;
|
|
2137
2166
|
}
|
|
2167
|
+
|
|
2168
|
+
//if(typeof(node.getAttribute(attributeName)) == 'undefined' && typeof(node[attributeName]) == 'undefined'){
|
|
2169
|
+
// //这个tag标签没有这个 attribute,忽略
|
|
2170
|
+
// continue
|
|
2171
|
+
//}
|
|
2172
|
+
|
|
2138
2173
|
//加入翻译
|
|
2139
|
-
translate.addNodeToQueue(uuid, node,
|
|
2174
|
+
translate.addNodeToQueue(uuid, node, attributeValue, attributeName);
|
|
2140
2175
|
}
|
|
2141
2176
|
|
|
2142
2177
|
}
|
|
@@ -2159,7 +2194,6 @@ var translate = {
|
|
|
2159
2194
|
if(node == null || typeof(node) == 'undefined'){
|
|
2160
2195
|
return;
|
|
2161
2196
|
}
|
|
2162
|
-
//console.log(node)
|
|
2163
2197
|
if(node.parentNode == null){
|
|
2164
2198
|
return;
|
|
2165
2199
|
}
|
|
@@ -2216,6 +2250,7 @@ var translate = {
|
|
|
2216
2250
|
//console.log('addNodeToQueue -- '+nodeAnaly['node']+', text:' + nodeAnaly['text']);
|
|
2217
2251
|
translate.addNodeToQueue(uuid, nodeAnaly['node'], nodeAnaly['text']);
|
|
2218
2252
|
}
|
|
2253
|
+
|
|
2219
2254
|
//console.log(nodeAnaly);
|
|
2220
2255
|
/*
|
|
2221
2256
|
//console.log(node.nodeName+', type:'+node.nodeType+', '+node.nodeValue);
|
|
@@ -2547,7 +2582,7 @@ var translate = {
|
|
|
2547
2582
|
//获取当前是什么语种
|
|
2548
2583
|
//var langs = translate.language.get(text);
|
|
2549
2584
|
var textRecognition = translate.language.recognition(text);
|
|
2550
|
-
langs = textRecognition.languageArray;
|
|
2585
|
+
var langs = textRecognition.languageArray;
|
|
2551
2586
|
//console.log('langs');
|
|
2552
2587
|
//console.log(langs);
|
|
2553
2588
|
|
|
@@ -4782,6 +4817,9 @@ var translate = {
|
|
|
4782
4817
|
}
|
|
4783
4818
|
//加入浏览器默认语种 v3.6.1 增加,以便更好的进行自动切换语种
|
|
4784
4819
|
data.browserDefaultLanguage = translate.util.browserDefaultLanguage();
|
|
4820
|
+
if(typeof(translate.enterprise.key) != 'undefined' && typeof(translate.enterprise.key) == 'string' && translate.enterprise.key.length > 0){
|
|
4821
|
+
data.key = translate.enterprise.key;
|
|
4822
|
+
}
|
|
4785
4823
|
|
|
4786
4824
|
if(typeof(data) == 'string'){
|
|
4787
4825
|
params = data; //payload 方式
|
|
@@ -5378,7 +5416,9 @@ var translate = {
|
|
|
5378
5416
|
translate.service.name = 'client.edge';
|
|
5379
5417
|
}
|
|
5380
5418
|
}
|
|
5381
|
-
}
|
|
5419
|
+
},
|
|
5420
|
+
/* 企业级翻译通道的key, v3.12.3.20250107 增加,针对打包成APP的场景 */
|
|
5421
|
+
key:'',
|
|
5382
5422
|
},
|
|
5383
5423
|
|
|
5384
5424
|
/*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "i18n-jsautotranslate",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.5",
|
|
4
4
|
"description": "Two lines of js realize automatic html translation. No need to change the page, no language configuration file, no API key, SEO friendly!",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|