前端翻译国际化
标签: 网站国际化支持
在网站中加入:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85<script> var langPackage = { "主题": "Title", "下一页": "NextPage", "末页": "LastPage", "首页": " FirstPage ", "上一页": " PreviousPage ", "待办工作": "MyTasks", "中": "Middle", "每页": " EachPage ", "条": " Record ", "共": " Total ", "页": " Page ", "第": " Current ", "工作主题": " ProcTitle" }; /* 主调函数 在 Jquery的 .read方法里调用 ReplaceChildChs($(document)); 或者页面的最后调用 ReplaceChildChs($(document)); */ function ReplaceChildChs(nodeObj) { // if($("#hdfUseLang").val()=="CN")return; if (nodeObj.children().length > 0) { nodeObj.children().each(function() { ReplaceChildChs($(this)); // if ($(this)[0].nodeName.toUpperCase() == "TD"){ FindChsAndReplaceIt($(this)); // } }); } else { FindChsAndReplaceIt(nodeObj); } } // 直接替换html 的一种设想,但总是报错 function JustReplaceChsDom(nodeObj) { var pat = new RegExp("[u4e00-u9fa5]+", "g"); // 匹配中文的正则表达式 var str = $(nodeObj).html(); while ((arr = pat.exec(str)) != null) { if (langPackage[arr[0]]) { str = str.replace(arr[0], langPackage[arr[0]]); } } $(nodeObj).html(str); } function FindChsAndReplaceIt(nodeObj) { var pat = new RegExp("[u4e00-u9fa5]+", "g"); if ((nodeObj.text() || nodeObj.val() || nodeObj.attr("title")) && (pat.exec(nodeObj.text()) || pat.exec(nodeObj.val()) || pat.exec(nodeObj.attr("title")))) { var str = "" if (nodeObj.text()) { str = nodeObj.text(); ReplaceValue(str, nodeObj, "text"); } if (nodeObj.val()) { str = nodeObj.val(); ReplaceValue(str, nodeObj, "val"); } if (nodeObj.attr("title")) { str = nodeObj.attr("title"); ReplaceValue(str, nodeObj, "title"); } } } function ReplaceValue(str, nodeObj, attrType) { var arr; var pat = new RegExp("[u4e00-u9fa5]+", "g"); while ((arr = pat.exec(str)) != null) { if (langPackage[arr[0]]) { str = str.replace(arr[0], langPackage[arr[0]]); if (attrType == "text") { nodeObj.text(str); } else if (attrType == "val") { nodeObj.val(str); } else if (attrType == "title") { nodeObj.attr("title", str); } } } } ReplaceChildChs($(document)); </script>
上面数组进行单词替换;
文章啥的最好还是有多语言的支持
translate翻译方式 需要翻墙
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19<div id="google_translate_element"></div> <script> function googleTranslateElementInit() { new google.translate.TranslateElement({ pageLanguage: 'zh-CN', layout: google.translate.TranslateElement.InlineLayout.SIMPLE }, 'google_translate_element'); } </script> <script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script> <!-- Begin TranslateThis Button --> <div id="translate-this"><a href="http://translateth.is/" class="translate-this-button">Translate</a></div> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript" src="http://x.translateth.is/translate-this.js"></script> <script type="text/javascript"> TranslateThis(); </script> <!-- End TranslateThis Button -->
整体项目思路:
文章同步发布到我的blog: 传送门
最后
以上就是唠叨流沙最近收集整理的关于 网站国际化 前端翻译(多语言)解决方案前端翻译国际化的全部内容,更多相关内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复