If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

I've had a look around re: callback.
It seems that you need to understand (first) what is actually happening.

In reality, I don't know what event is occurring & ending.

Obviously I know that my text has been sent to google, and that it is returning (modified).

Clearly a change of state is: triggered - not finished - finished.

But worse than that.... the page first loads fully ie. one state complete; and then there is a pause while the text is sent to google (ie. the first state is still stable). Then the returned translated text is written in.

If we know what the final state is, then we might compare it to the the 1st state - which is page loaded and original text written in (if any, cos iframe2 is originally empty, but it will gradually acquire text, as it is typed into iframe1).

What we can be certain of, is that the 2nd completed state, is going to be different to the 1st completed state.

Perhaps it's possible to monitor the sending to google of the original text.
Ie. English arrives in iframe2. It is then sent, or called, to google.
This 'data transmission' might then allow the 1st state to be logged.

The 2nd state (different) could be compared to the 1st, but can we determine, when the return text has fully arrived?

I think once we understand how javascript can recognise these events, then the appropriate function can be fired.

I had already blanked the local storage cache for iframe2 & iframe3 by passing the empty textarea thru localstorage to iframe2 which passed it on to iframe3

As a result, this is what the log shows (I deleted the old logs):

Step 1
Therefore as chrome loaded: iframe2 & 3 loaded, and their scripts fired with almost no data.

Step 2
I pasted some english text using ctr+v into textarea.
onClicked the text.
The text was localstored
iframe2 reloaded, retrieving the text, and displaying it in english.
The text was then sent to google.
It was returned in French, and displayed.

Step 3
Step 3 already started probably milliseconds after onclicking the text.
iframe3 had reloaded retrieving the blank local storage.

This is the problem area, pausing the rolling reload, until translate has done its biz

Step 4
I onclicked iframe2, causing the translated text to go to localstorage.
iframe3 reloaded, retrieving the French text.
The text was sent to google.
It was returned in English, and displayed.

Step 5
I quit chrome, and copied the log to temp.
I copied the log to pastebin.

I am wondering about the need for local storage here, which has growing support but not below IE8. Also your interface is a little unintuitive - you can pass the value of the textarea to the iframe onkeyup and do it that way. Here's one way, anyway. Main page:

Users who have thanked xelawho for this post:

I am wondering about the need for local storage here, which has growing support but not below IE8. Also your interface is a little unintuitive - you can pass the value of the textarea to the iframe onkeyup and do it that way.

Yes, you are absolutely right.
I used onclick purely so that I could control events.

The system is primarily set up as a test bed for the scripting.

My idea was ultimately to use the 'Enter' key, to act on the finalisation of a paragraph: Type a paragraph - have a look (how did it turn out) continue, or have another go.

Onkeyup may be more akin to the google translate page, where characters are sent individually, building a paragraph that is ultimately translated.

But either way, the thinking was that, the final processes would inform the final design.

Re your suggested code..... it looks like you have discerned the key commands.

I was working with what was auto-available (from ignorance of the detail).

This enlightenment, means I need to spend a bit more time understanding what is happening - but at least I know now, where to look.

The log file has proved definitely to be good educational material, even for the uninitiated (who are prepared to go thru each line a couple of times).

yes. there is a problem though - there doesn't seem to be a way to auto select the language - and therefore have an automatic translation - on first page load (if you have done this already you would have to clear your cache to see what I am talking about). You would think that the autoDisplay parameter might do something, but from what I can tell setting it to true, false or even removing it completely seems to have no effect at all

The good news is that the system now only requires the removal of one "onClick" event handler.
more on that later.

Originally Posted by xelawho

there doesn't seem to be a way to auto select the language - and therefore have an automatic translation - on first page load (if you have done this already you would have to clear your cache to see what I am talking about).

It's purpose is to auto-select the 'from & 'to' languages.
With this added & using google chrome, I have seen no problems.
I cleared the cache, but the scripts & display functioned as expected.
For no other reason that this, I believe the anchor link must solve this problem.

Originally Posted by xelawho

You would think that the autoDisplay parameter might do something, but from what I can tell setting it to true, false or even removing it completely seems to have no effect at all

This looks as though it is driven by whether: the text SHOULD be translated, or whether it HAS been translated.

Once translated, it must be displayed. Based upon an understandable philosophy that is effectively: "Be aware, this data has been modified".
Therefore the question is only whether it is always displayed, when say a French browser, visits English pages.

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?

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.

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.