binarylime Posted June 1, 2008 Share Posted June 1, 2008 Hi, I am sending in an array of sentences to google language translation API. The sentences return and are displayed on screen. Every now and then, & # 3 9 appears (without spaces). As far as I know this is the escape character for the apostrophe? I've tried unescape(string); - but it doesn't appear to work. The code is at http://development.asclarke.com/modliatranslator.html Any idea? Cheers Quote Link to comment Share on other sites More sharing options...
kbh43dz_u Posted June 1, 2008 Share Posted June 1, 2008 str_replace("& # 3 9","",$string); ? Quote Link to comment Share on other sites More sharing options...
binarylime Posted June 1, 2008 Author Share Posted June 1, 2008 No good unfortunately. It's just JavaScript - no PHP. Heres the code: <script type="text/javascript"> google.load("language", "1"); window.onload = function() { //Store original content to global variable original = document.getElementById("translation").firstChild.nodeValue; } //Clear content from the existing element function clearElement(translation) { //While element has children, remove them while(translation.firstChild) translation.removeChild(translation.firstChild); } //Do the translation function initialize(value) { //Get language to translate to var translateto = value; //Declare array to store chunks of text var myArray = new Array(); //Split page text at every full stop into array elements myArray = original.split('.'); //Call function to remove existing text from page clearElement(document.getElementById("translation")); /* //Test function. Prints out elements of array before translation to verify split function for (var i=0; i<myArray.length; i++) { document.getElementById("translation").appendChild(document.createTextNode("["+i+"]")); document.getElementById("translation").appendChild(document.createTextNode(myArray[i])); document.getElementById("translation").appendChild(document.createTextNode(". ")); } */ var i=0; //AJAX is asynchronous. Sentences sent in parallel for transaltion but may not return in //right order, therefore wrap incrementation of array counter in recursive function //Important. This varibale must be pre defined so that doTranslation can add to it translated = ""; function doTranslation() { if(myArray[i]) { google.language.translate(myArray[i], "en", translateto, function(result) { if (!result.error) { //concatinate translated text into string translated = translated + result.translation + ". "; //document.getElementById("translation").appendChild(document.createTextNode("["+i+"] ")); //document.getElementById("translation").appendChild(document.createTextNode(result.translation)); //document.getElementById("translation").appendChild(document.createTextNode(". ")); i++; doTranslation(); } }); } else { //When translation is complete, call display function display(); } } //Display "Please wait" message document.getElementById("translation").appendChild(document.createTextNode("Please wait; translating text...")); //Call function to perform translation doTranslation(); //Display translated text function function display() { translated.replace(translated, "'","\x27") document.getElementById("translation").appendChild(document.createTextNode(translated)); } } </script> Hope that helps explain what i'm after. The translation works and prints the sentences to the screen. But when translating to French for example, there are lots of apostrophise in French words. But for some reason, rather than putting in apostrophise, it shows the html escape character for apostrophe. I've tried string.replace("'", "'") and unescape(string) but no luck... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.