views:

193

answers:

2

Iam using a mixed approach of manual language translation, and google translation using jquery-translate libray. I have gotten the google method to work correctly, but google is missing some languages my employer's client requires...

So I am using jquery to read an xml file that has english + french canadian languages, for a sample page, I am able to read the xml,and to use nodeContainsText to replace text on a page, however when I do so. the text's accents that are displayed perfectly via google translation ie french.

So my problem is how do i get the xml data as a correct charset/content type, so as to display that correctly.

$(document).ready(function()
{
  $.ajax({
    type: "GET",
    url: "xmldata.xml",
    dataType: "xml",
    success: parseXml
  });
});
function parseXml(xml)
{

  //find every Tutorial and print the author
  $(xml).find("english").each(function()
  {
    $(this).find('phrase').each(function(){
        english[count] = $(this).text();
        console.log('Adding to english array..['+english[count]+']');
        count = count + 1;
    });
  });
  count = 1;
  $(xml).find("french_canadian").each(function()
  {
    $(this).find('phrase').each(function(){
        frca[count] = $(this).text();
        console.log('Adding to frca array..['+frca[count]+']');
        count = count + 1;
    });
  });

$('body').nodesContainingText().each(function(){

    // step 1 search through all text nodes

    var $el = $(this), text = $el.text() || $el.val();
    var nn = this.nodeName;


    // step 2 find position in english array for word
    for(var i=0;i<english.length;i++) {
        // step 3 replace with french canadian version from array
        if (english[i] == text) {
            // which node dot text = value
            console.log('Replacing...'+english[i]+' with '+frca[i]);
            $el.text(frca[i]);
        }
    }
});

}

As you can see I am using console.log via firebug to help debug where the content/charset issue comes from...

I just can't seem to grasp the syntax to convert the data incoming from the xml file into a correct htmlentities coding..

I know it's supposed to be .html() but when i add that, it just causes errors. So can someone give me a clue?

Thank You.

A: 

is the html document served as utf-8?

just somebody
I don't think the html document has a doctype, but the google translation displays teh accents correctly, but when i do my manual translation it does not. So it can't be the html doctype that's the issue.
crosenblum
A: 

I eventually found the solution by changing the charset of the xml file directly to

That made all the accents from other languages instantly viewable...

Thanks.

crosenblum