开发者

jQuery Language Translation is not working?

I want to translate my html page from English to arabic and arabic to english.

I am using "jquery.translate.js" plugin. this plugin will translate my language

Am using json file to indicate the changes in the language using span id of the HTML elements. langfiles-ar-SA.json

  {
  "ProfileSpan开发者_如何学运维" : "Profile",
  "FrinedsSpan" : "Invite",
  "FreepointsSpan" : "Points",
  "PhonenumberSpan" : "Phone",
  }

similarly another json file as langfiles-ar-SA.json

  {
  "ProfileSpan" : "المل�",
  "FrinedsSpan" : "دعوة",
  "FreepointsSpan" : "النقاط",
  "PhonenumberSpan" : "بحث متقدÙ",
  }

In html I added the three js files js/jquery.js, js/jquery.translate.js, js/translationManagement.js The json files are in the folder in the webcontent. My javascript is:

    function Intialize(){
 $('#EnglishLanguageLink').click(function() {
  var eng = 'en-US';
  changeLanguage(eng);
  return false;
     });
$('#ArabicLanguageLink').click(function() {
    var ara = 'ar-SA';  
  changeLanguage(ara);
  return false;
     });
    }

    function changelanguage(newLanguage){
     $(this).translate("languages/langfiles.json", newLanguage);
    }

If I click the english language link and tamil language link it goes to the top of the page. But the translation doesnt happen. What error am doing. Please suggest a way to solve this. Any suggestions Please? Thanks in Advance.


I think your problem may be because your changelanguage function will actually be running in the window object's scope. This means that this in changelanguage() will actually be referencing the window object and not the other elements. To fix this, pass the object into your function like so:

function changelanguage(newLanguage, obj){
    $(obj).translate("languages/langfiles.json", newLanguage);
}

And then in your click handlers, change the call to this:

changeLanguage(eng, this);

And obviously change eng for the Arabic link.

I'm not entirely sure if that's what variable .translate should be running on, but it seems weird that you would run it on the window object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜