dcsimg
Modifying the DOM?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   gustaf_giebel
Posted On:   Wednesday, September 19, 2007 05:01 PM

Hi I want to send a selected text to the google translator (http://www.google.com/translate_t) and insert the translated text on the fly into the DOM of the page, so that it replaces the old text. Now the problem: I only send the text to google translate and get a text back (without the tags) - but how do I keep the html-tags, so that when I insert the translated text into the DOM, it displays correctly? For example you have " Some text and some bold words. ". The user selects "Some text and some bold words.", it gets translated, and inserted back in as "Etwas Text und einige fette Wörter." But the tags are missing and it doesn't display correctly. I do it this way:    More>>

Hi
I want to send a selected text to the google translator (http://www.google.com/translate_t) and insert the translated text on the fly into the DOM of the page, so that it replaces the old text.
Now the problem: I only send the text to google translate and get a text back (without the tags) - but how do I keep the html-tags, so that when I insert the translated text into the DOM, it displays correctly?

For example you have "

Some text and some bold words.
". The user selects "Some text and some bold words.", it gets translated, and inserted back in as "Etwas Text und einige fette Wörter." But the tags are missing and it doesn't display correctly.

I do it this way:

var range = text.getRangeAt(0);
range.deleteContents();
newnode = document.createElement("a");
newnode.appendChild(document.createTextNode(translated_text));
range.insertNode(newnode);

How can I overcome this and re-insert the tags in the right place?

Any help would be appreciated.    <<Less

Re: Modifying the DOM?

Posted By:   Christopher_Koenigsberg  
Posted On:   Sunday, October 7, 2007 03:42 PM

You are asking, basically, how to take the English phrase, translate it as a whole, and then, after the fact, given the translation of the whole phrase, you seem to think you can extract the corresponding German words (out of the overall German phrase), matching them up exactly to some English words in the original phrase. I'm guessing that sometimes it will be easy, depending on the actual phrase, but sometimes it will impossible. Maybe there will be phrases where the marked-up sub-phrase, in the source language, will 'disappear' in the target language? or be divided up in a different way so the sub-phrase's translation is no longer contiguous? etc. I'm guessing that you'll have better luck with English and German, than you would with other pairs of languages.



Maybe you need to do your translation piece by piece, submitting the marked up (bold) text separately from the rest of the phrase?
About | Sitemap | Contact