Easily integrate Google Translate into your web App with jquery.
1. [Code][javascript] Code
?
1<script src= "Scripts/translatorscript.js" type= "Text/javascript" ></script>
?
2 [Code]loadscript, setting the path
?
? 1LoadScript (ScriptPath + "jquery-blockui.js");
2LoadScript (ScriptPath + "jquery.translate-1.4.7.min.js");
3LoadScript (ScriptPath + "jquery.cookie.js");
? 3.Code [JavaScript] Code
01function Getscriptspath () {
Scripts var = document.getelementsbytagname ("script");
The var regex =/(. *\/) translatorscript/i;
for (var i = 0; i < scripts.length; i++) {
var currentscriptsrc = scripts[i].src;
if (Currentscriptsrc.match (regex))
Currentscriptsrc.match (regex) [1];
08}
09
return null;
11}
4.Code]loadtranslator
01function Loadtranslator () {
02
$.translate (function () {
04
try {
$ (' #translate-bar '). HTML ("");
07}
The catch (e) {
09}
10
One-to-one var selectedlanguage = $.cookie (' selectedlanguage '); Get previously translated language
12
if (selectedlanguage) {
if (selectedlanguage! = ' en ')
Translateto (Selectedlanguage);
16}
17
function Translateto (selectedlanguage) {
$ (' body '). Translate (' 中文版 ', Selectedlanguage, {
Not: '. Jq-translate-ui ',
Fromoriginal:true,
Start:function () {
$ (' #jq-translate-ui '). Val (selectedlanguage);
$.blockui.defaults.applyplatformopacityrules = false;
$.blockui (
26 {
Message: ' Language translation in Progress, please Wait ... ',
CSS:
29 {
border: ' None ',
padding: ' 10px ',
BackgroundColor: ' #000 ',
'-webkit-border-radius ': ' 9px ',
'-moz-border-radius ': ' 9px ',
Opacity:. 9,
Color: ' #fff '
37},
Overlaycss: {backgroundcolor: ' #000 ', opacity:0.6, '-moz-opacity ': ' 0.6 ', Width: ' 100% ', Height: ' 100% '}
39});
40},
Complete:function () {$.unblockui ({css: {cursor: ' Default '}});
42});
43}
+//Languages is loaded into the selection box
$.translate.ui ({CSS3 effects
Tags: ["select", "option"],
//a function that filters the languages:
-Filter: $.translate.istranslatable,//this can be an array of languages/language codes too
//a function that returns the text to display based on the language code:
50 Label: $.translate.tonativelanguage | |http://www.huiyi8.com/css3/?
51 function (langcode, lang) {return $.translate.capitalize (LAN g); },
52 //whether to include the UNKNOWN: ' Along with the languages:
53 ; Includeunknown:false
54 }). Change (function () {
55 $.cookie (' Selectedlanguage ', $ (this). Val (), {path: '/'});
56 Translateto ($ (this). Val ());
57 return true;
58 }). AppendTo (' #translate-bar ');
59 });
60}