Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 43
  1. #16
    New Coder
    Join Date
    Nov 2012
    Location
    France
    Posts
    78
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Ace..... View Post
    The good news is that the system now only requires the removal of one "onClick" event handler.
    Hang on.... I'll answer your last post with another.

    The onkeyup code is working very well, in transferring the text to its designated division (then onward to google and therefore returning translated to the same designated area).

    The problem now is: how to pass the translated text back to google?

    The requirement being; that the user should only be interested in typing the text.
    The onkeyup deals with that perfectly, for the first translation.

    What is needed is a way to fire a script, when the translation has arrived.
    I'm doing this with onclick, just to prove that everything is working fine.
    And it is.

    As an alternative I note lines 173 to 176 ( http://pastebin.com/016QNsSz )

    Code:
    [3726:3754:5520733244:VERBOSE1:resource_loader.cc(293)] OnResponseStarted: http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit
    [3726:3754:5520734105:VERBOSE1:resource_loader.cc(320)] OnReadCompleted: "http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit" bytes_read = 1477
    [3726:3754:5520734658:VERBOSE1:resource_loader.cc(320)] OnReadCompleted: "http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit" bytes_read = 0
    [3726:3754:5520734707:VERBOSE1:resource_loader.cc(543)] ResponseCompleted: http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit
    Could "ResponseCompleted" be the code element that could fire the script to pass the translated text back to google?

    Here is how I'm doing it, just to prove the text can be re-translated and passed into a 2nd iframe:

    Code:
    <div id="google_translate_element"></div> 
    <div id="thetext" onClick="translateIt(document.body.innerText)"></div>
    
    <script type="text/javascript"> 
    function translateIt(text) { parent.window.frames['theframe2'].googleTranslateElementInit(text); } 
    </script>
    I guess I can be a bit more accurate with the text value, but as it stands, with a click on the text, the 2nd translation occurs.

  2. #17
    New Coder
    Join Date
    Nov 2012
    Location
    France
    Posts
    78
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by xelawho View Post
    can I ask what the purpose of the other iframe is? it seems to want to translate to English? But if the input language is English what is the idea? and why not fire the function on the onkeyup of the textarea the way you do with the first iframe?
    The idea is simply to gain feedback.
    Google doesn't translate textarea content, hence why we must first send it to be written in to the page, in order for it to be read.

    Quote Originally Posted by xelawho View Post
    also, this is going to cause you problems:
    Code:
    <body onhaschange="translateIt(document.body.innerText)">
    there is, sadly, I believe, no body onhaschange event, and the equivalent is hard to implement in a cross-browser fashion.
    Yes, I should have deleted that..... I was merely floundering around looking to see if there was an event handler that would work..... and there were none.

    Quote Originally Posted by xelawho View Post
    innerText will get you into trouble, too. innerText is IE only. textContent is more widely accepted, but IE only started recognising it at IE9+

    if you are only looking to translate the text from the textarea, it is much easier just to be getting the value of that textarea, the same as you are doing now.
    All fair comment.
    This whole area of standardisation is in a mess, and should have been sorted out some years back (considering the dates of some of the articles I've read, discussing this very issue).

    My thinking with this thread, was to focus on establishing the scripts that could pass either the text or dom elements, to and from google.
    In effect treating the two problems separately.

    On the question of "what to transfer":

    Logic Ali produced a very good piece of coding to operate in this area:
    (How to) Copy/Manipulate all parsed output/displayed text for use as real text?

    Here is another interesting behemoth, apparently working across all browsers.
    http://clubajax.org/examples/plain-t...-vs-innertext/

    I stopped working on this issue, when I discovered there were problems working with line breaks, as the text moved backwards and forwards.

    I figured that once I had a working system in place, I could then experiment with greater ease.

    But clearly crossbrowser/generation compatibility is a nightmare, that hopefully can be dealt with, with community assistance coming from:
    (How to) Copy/Manipulate all parsed output/displayed text for use as real text?

  3. #18
    New Coder
    Join Date
    Nov 2012
    Location
    France
    Posts
    78
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Re: Feedback

    try this:

    1. Stewart Francis - "You know who really gives kids a bad name? Posh and Becks."
    2. Tim Vine - "Last night me and my girlfriend watched three DVDs back to back. Luckily I was the one facing the telly. "
    3. Will Marsh - "I was raised as an only child, which really annoyed my sister."
    4. Rob Beckett - "You know you're working class when your TV is bigger than your book case."
    5. Chris Turner - "I'm good friends with 25 letters of the alphabet… I don't know Y."
    6. Tim Vine - "I took part in the sun tanning Olympics - I just got Bronze."
    7. George Ryegold - "Pornography is often frowned upon, but that's only because I'm concentrating."
    8. Stewart Francis - "I saw a documentary on how ships are kept together. Riveting!"
    9. Lou Sanders - "I waited an hour for my starter so I complained: 'It's not rocket salad."
    10. Nish Kumar - "My mum's so pessimistic, that if there was an Olympics for pessimism… she wouldn't fancy her chances."

    Not funny.
    (Perhaps they never were to begin with )

  4. #19
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,774
    Thanks
    55
    Thanked 518 Times in 515 Posts
    I'm not sure what the gaining of feedback means here.

    Is the purpose to send text to google to translate, then send the translated text to google to translate back to the original language so as to compare the original with the twice-translated text?

  5. #20
    New Coder
    Join Date
    Nov 2012
    Location
    France
    Posts
    78
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Yes.
    Hence the jokes.

    Sure jokes are the worst to translate.
    I used them merely as an example.

    I put ten in to show that in fact, it wasn't all disaster.

    Pretty close.... but pretty close often is just not good enough.

    Consider:

    We will accept cheques & we will not accept cheques.

  6. #21
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,774
    Thanks
    55
    Thanked 518 Times in 515 Posts
    as Ali pointed out (I think in the other thread), the most reliable way to do this would be to use the translate API - I note that it does offer a callback function, which lets you know when the translated text has arrived back from google.

    the thing you're working with on the other hand is a simple widget and as far as I can tell does not offer the sort of functionality you need here.

    but in the meantime, you can use a (fairly) simple workaround - check every half a second (or whatever - you can change the 500 in the code, which refers to miliseconds, although that seems reasonable to me) to see if the text that appears in the "French" iframe is the same as the text that was entered in the textarea. If it has changed (ie, google has sent back its results), send the new text on to the next iframe for translation back to English.

    It's not 100%, but seems to work ok most of the time. You might get better results by lengthening the delay, or using a button to fire the functions instead of onkeyup.

    main page:
    Code:
    <html>
    <head>
    </head>
    <body>
    <textarea name="styled" id="styled" onkeyup="translateIt(this.value)"></textarea>
    <iframe name="theframe" width="500" src="translated.html#googtrans(en|fr)"></iframe>
    <iframe name="frame2" width="500" src="orig.html#googtrans(fr|en)"></iframe>
    <script type="text/javascript">
    function translateIt(text) {
    var text=text.replace(/\n/g,"<br>")
    parent.frames['theframe'].googleTranslateElementInit(text);
    }
    </script>
    </body>
    </html>
    translated.html:
    Code:
    <html>			
    <head>
    <meta name="google-translate-customization" content="f3ec1860041f93e1-f800c17a206199a4-g305246f186c2820d-15"></meta>
    <script type="text/javascript" src="//translate.google.com/translate_a/element.js"></script>
    </head>
    <body>
    <div id="thetext"></div>
    <script type="text/javascript">
    var thetext;
    function googleTranslateElementInit(txt) {
    thetext=txt;
    document.getElementById("thetext").innerHTML=txt;
    new google.translate.TranslateElement({pageLanguage: 'en', includedLanguages:'fr',layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL, autoDisplay: false});
    setTimeout(checkIt,500)
      }
      
    function checkIt(){
    var thediv=document.getElementById("thetext")
    res=thediv.innerText?thediv.innerText:thediv.textcontent;
    if(thetext!=res){
    parent.frames['frame2'].googleTranslateElementInit(thediv.innerHTML);
    	} else{
    setTimeout(checkIt,500)	
    	}
    }  
    </script>
    </body>
    </html>
    orig.html:
    Code:
    <html>
    <head>
    <meta name="google-translate-customization" content="f3ec1860041f93e1-f800c17a206199a4-g305246f186c2820d-15"></meta>
    <script type="text/javascript" src="//translate.google.com/translate_a/element.js"></script>
    </head>
    <body>
    <div id="origtext"></div>
    <script type="text/javascript">
    
    function googleTranslateElementInit(txt) {
    document.getElementById("origtext").innerHTML=txt;
      new google.translate.TranslateElement({pageLanguage: 'fr', includedLanguages:'en',layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL, autoDisplay: false});
      }
    </script>
    </body>
    </html>
    something else I just noticed is that, while it's reasonably reliable in Chrome and IE, firefox returns "undefined" in the translated-back-to-original frame. Dunno why, and being that my work made me install this stupid extension for firefox that makes firebug unuseable I can't see why that would be, either.

    Maybe someone else can take a look.
    Last edited by xelawho; 11-13-2012 at 03:25 AM.

  7. Users who have thanked xelawho for this post:

    Ace..... (11-13-2012)

  8. #22
    New Coder
    Join Date
    Nov 2012
    Location
    France
    Posts
    78
    Thanks
    20
    Thanked 0 Times in 0 Posts
    A working version is now ready.
    This should satisfy any doubts over whether reverse translation has become possible in 2012.

    Passing French back to English
    This was the killer coding problem.

    I've solved this with the aid of an open source javascript library for keyboard shortcuts:


    I chose Ctrl+shift to trigger the reverse translation, simply because the user can type at will, and when ready, hit the 2 keys that are (I believe) usually bottom left.

    Bugs
    I experienced one problem, by hitting the shortcut before the text had finished translating.
    This stopped the primary translation process.
    Everything I typed in English was curiously accurate.
    I then discovered that I was simply moving English from page 1 to 2 to 3.

    This bug has never appeared again.
    I reloaded the page and it worked perfectly thereafter.

    Edit Note: This may be to do with the fact that by pressing Ctrl+shift this also creates an onkeyup event.
    When I used onclick, the translated text simply transferred to the right frame.
    Now the shortcut resends the english text for translation, at the same time as it trys to transfer the translated text.

    That is the cause of the bug, so the instructions below don't help.
    A fix is required.

    To get around this, in the instructions I recommend checking what you have typed, before translating it back to English. (In real life, you would first check what you'd written)

    Yes.......... I know it is not perfect.

    Perfect would be to automatically pass the French, after translation.
    But....... as a test bed; this is pretty good (and maybe a solution will present itself). In the meantime, other problems might arise from usage.

    Anyway, here it is:
    You'll see there are some valuable instructions with it, based on my experience of translation.
    Last edited by Ace.....; 11-11-2012 at 05:49 PM.

  9. #23
    New Coder
    Join Date
    Nov 2012
    Location
    France
    Posts
    78
    Thanks
    20
    Thanked 0 Times in 0 Posts
    I updated the the two problem files around 14:00GMT.
    I had two onclick events, one being correct, the other incorrect.

    It now appears quite stable, with all the logged errors/warnings originating from the google code (as listed below).

    Having now coded the mouse click over the textarea to update the reverse translation....... it seems quite fluid.

    Yes.... it is still possible to interrupt the initial translation, however, having tidied the code, the translation now simply picks up when new text is entered.

    There can be temporary hanging (for a few seconds), but this may well be the fault of the network or at google end.
    No warnings appeared when this happened, and the translation just started again.

    Overall, this afternoons version is better than yesterday afternoons!

    Warnings relating to google code:

    Code:
     [15:10:04.275] Unknown property '-moz-box-shadow'.  Declaration dropped. @ http://translate.googleapis.com/translate_static/css/translateelement.css:2
    [15:10:04.275] Unknown property 'zoom'.  Declaration dropped. @ http://translate.googleapis.com/translate_static/css/translateelement.css:2
    [15:10:04.275] Expected declaration but found '*'.  Skipped to next declaration. @ http://translate.googleapis.com/translate_static/css/translateelement.css:2
    [15:10:04.277] Error in parsing value for 'display'.  Declaration dropped. @ http://translate.googleapis.com/translate_static/css/translateelement.css:2
    [15:10:04.277] Unknown property '-moz-border-radius'.  Declaration dropped. @ http://translate.googleapis.com/translate_static/css/translateelement.css:2
    [15:10:04.278] Error in parsing value for 'background'.  Declaration dropped. @ http://translate.googleapis.com/translate_static/css/translateelement.css:2
    [15:10:04.278] Error in parsing value for 'filter'.  Declaration dropped. @ http://translate.googleapis.com/translate_static/css/translateelement.css:2
    [15:10:04.279] Expected color but found 'top'.  Error in parsing value for 'background'.  Declaration dropped. @ http://translate.googleapis.com/translate_static/css/translateelement.css:2
    [15:10:04.279] Error in parsing value for 'background-image'.  Declaration dropped. @ http://translate.googleapis.com/translate_static/css/translateelement.css:2
    [15:10:04.280] Expected color but found 'top'.  Error in parsing value for 'background-image'.  Declaration dropped. @ http://translate.googleapis.com/translate_static/css/translateelement.css:2
    [15:10:04.281] Unknown pseudo-class or pseudo-element 'null'.  Ruleset ignored due to bad selector. @ http://translate.googleapis.com/translate_static/css/translateelement.css:2
    [15:10:04.282] Unknown property 'box-sizing'.  Declaration dropped. @ http://translate.googleapis.com/translate_static/css/translateelement.css:2
    [15:12:16.659] Use of attributes' nodeValue attribute is deprecated. Use value instead. @ http://translate.googleapis.com/translate_static/js/element/10/element_main.js:300

  10. #24
    New Coder
    Join Date
    Nov 2012
    Location
    France
    Posts
    78
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Since adding the doc & character declarations, and tidying some of the unacceptable declarations and comment marks......

    ..... it all seems fine now, in the big 3.

    I don't know whether it's to do with the network, or whether it's down to the improvements made to the coding (probably the latter) - but everything is running much faster now.
    So fast in fact that, whilst typing, it is hard to click the mouse fast enough to interrupt the primary translation.
    I had to paste in text and click, to mimic this scenario.

    As it happens, there seems to be no problem.
    If the translation is interrupted (and English is displayed), by simply recommencing the typing, the translation continues.

    Having said that...... I'm game to try to fully automate the system (eliminate the mouse click).
    I just don't know where to start.

    Does anybody have any pointers?

  11. #25
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,774
    Thanks
    55
    Thanked 518 Times in 515 Posts
    did you try with the method described in post 21, above?

  12. #26
    New Coder
    Join Date
    Nov 2012
    Location
    France
    Posts
    78
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by xelawho View Post
    did you try with the method described in post 21, above?
    I don't know why; I don't know how...... but sometimes fate deals a good hand.

    ( it's rare though )

    I actually missed that post (see first remark)...... I guess it was meant to be like that.

    After the weekend's work, and Sunday, sort of stupidly releasing a working version (in the heat of the moment). Today saw good housekeeping, leading to 'covering the fundamentals': getting all the declarations right (when a release would have been correct).

    There's only a break-line that Chrome doesn't like (actually W3c).
    Oh, while I remember re W3c: onhaschange does exist. It's part of a whole new raft of event handlers in HTML5 (what a bugger eh? )

    Either way.... I didn't manage to use it correctly.
    http://www.w3.org/TR/2009/WD-html5-2...rs.html#window

    But leaving all that aside, this really IS the ideal point to move to the next phase.
    This morning would have been too early.
    Definitely a lesson to be learned there IMHO.

    Tomorrow, may well see full automation.

    (Thanks for the direction.)

  13. #27
    New Coder
    Join Date
    Nov 2012
    Location
    France
    Posts
    78
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by xelawho View Post
    something else I just noticed is that, while it's reasonably reliable in Chrome and IE, firefox returns "undefined" in the translated-back-to-original frame. Dunno why, and being that my work made me install this stupid extension for firefox that makes firebug unuseable I can't see why that would be, either.

    Maybe someone else can take a look.
    Yes you were right to flag this up.

    The sys is simply not working in FFox.
    It is the English text that is being transferred, rather than the French.

    Note: you can confirm this by hovering the mouse cursor over the supposed reverse translated text.
    The dialogue box should show the French source.
    However, it shows English as the source.

    Further; FFox console doesn't flag up any errors.

    Chrome does seem reliable.
    I did have problems, but I believe that was due to the fact that I had not fully stripped out my own code for focus, onclick, and Ctrl+shift.

    Also, when I first tried it; it was without the:
    Code:
    var text=text.replace(/\n/g,"<br>")
    It worked fine.

    When I introduced the variable, it created problems.

    I removed it, and Chrome was stable once again.
    This made no difference to FFox.

    Conclusion (theory)
    FFox is happy with the new automation code.
    But, the "if comparators" are reading the fr/en variables differently
    OR
    the variables are being streamed differently.
    OR
    'thetext' does NOT equal 'res' the moment new English text arrives.
    Therefore the English is sent (rather than the French).

    When English is typed, it appears in the Fr2En frame as English.
    It is written in, when the previous state of the frame was French.
    Ie. Could it be functioning back to front sending the wrong 'different' text.

    Well, we are certain that it is sending the wrong text.
    At least it's a start.

    Code:
    function checkIt(){
    var thediv=document.getElementById("thetext")
    res=thediv.innerText?thediv.innerText:thediv.textcontent;
    if(thetext!=res){
    parent.frames['theframe2'].googleTranslateElementInit(thediv.innerHTML);
    	} else{
    setTimeout(checkIt,500)	
    	}
    }

  14. #28
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,774
    Thanks
    55
    Thanked 518 Times in 515 Posts
    it seems to work ok for me. I put one of your jokes into your page using Firefox:
    You know you're working class when your TV is bigger than your book case

    the French version comes out
    Vous savez que vous êtes de la classe ouvrière lorsque votre téléviseur est plus grand que votre caisse de livre

    the translated back to English version shows
    You know you're working class When your TV is bigger than your book box

    (note that the W has been capitalized and "case" has been changed to "box")

    so obviously it's not just transferring the English straight across. Caching issues, maybe?

  15. #29
    New Coder
    Join Date
    Nov 2012
    Location
    France
    Posts
    78
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Be careful to hover the cursor over the reverse translated text.

    It seems VERY wierd.

    But what in fact is happening, is that the English source text is being converted to English.
    This produces a re-translation that makes a minor change..... but that is only going to make you think that it has been translated.

    Try typing this in Chrome & then in FFox:

    "Olivia is sad that she had a problem with her braces."

    You should get in Chrome:
    Orig English: Olivia is sad that she had a problem with her braces.
    French: Olivia est triste qu'elle avait un problème avec son appareil.
    Reverse English: Olivia is sad she had a problem with his camera.

    Hover over the French and you will see the original text.
    Hover over the reverse English and you will see the French text.

    In FFox:
    Orig English: Olivia is sad that she had a problem with her braces.
    French: Olivia est triste qu'elle avait un problème avec son appareil.
    Reverse English: Olivia is sad that she had a problem with her braces.

    Note: FFox struggles to display the dialogue box.
    Change tab, then return, and then hover.
    You will see that the reverse English is merely the original English.

    And anyway we know that google translate (with this sentence structure) translates 'braces' as 'camera'.

    You can prove this by clicking this link (containing the text).standard google translate page.... it translates it as camera.

    Presuming you see the same results; this will confirm that the sys is failing in FFox as previously described.

  16. #30
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,774
    Thanks
    55
    Thanked 518 Times in 515 Posts
    oh, dear

    this line
    Code:
    res=thediv.innerText?thediv.innerText:thediv.textcontent;
    should be:
    Code:
    res=thediv.innerText?thediv.innerText:thediv.textContent;
    change that, and Olivia gets sad about her camera in FF, too


  17. Users who have thanked xelawho for this post:

    Ace..... (11-13-2012)


 
Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •