prince2007g / multi-language-translation

Automatically exported from code.google.com/p/multi-language-translation
0 stars 0 forks source link

Cache is not getting cleared on Ajax #15

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. In My website i have a Div that is loaded dynamically by Ajax
After loading the div once i translate the page
it translates well

2.but when content of the div is changed by Ajax
and I run the script gain to translate
than the previous content(chased) one is loaded

3.And new content is lost

Can you provide any example websites/pages which demonstrate the
problem?

What is the expected output? What do you see instead?

What version of the script are you using? Have you made any changes to it?

What web browser (e.g. Firefox, Internet Explorer, etc), operating system
(e.g. Windows 7, Mac OS X, etc), and connection speed are you using?

Please provide any additional information below:

Original issue reported on code.google.com by schinsammy@gmail.com on 15 May 2011 at 8:03

GoogleCodeExporter commented 8 years ago
Please tell me how can i reset the cahce so that every time the Div is reloaded 
from Ajax and translation is done new content are loaded

Original comment by schinsammy@gmail.com on 15 May 2011 at 8:05

GoogleCodeExporter commented 8 years ago
I can confirm this is an issue with the current version of the script.

In fact, it's partly by design. Because Google cannot translate text perfectly, 
every time previously translated content is submitted, the quality of the 
translation degrades slightly more, until it eventually becomes meaningless. 
The script gets around this by building a cache of the original page content, 
and submitting only this content to google. Caches are also built after the 
content was translated to allow translations back to the same language to occur 
almost instantaneously.

However, if you want to clear these caches, you can do this by making sure that 
the following JavaScript code is run every time your AJAX script has updated 
the page:

GL_transContent = [];
GL_chunksTotal = 0;
buildChunkedContent();

Please note that by doing this, *all* of the current page content will be 
resubmitted to Google next time a translation is performed, so you may 
experience the following issues:

* If the page already contains content that's been translated by Google, the 
translation quality may get worse next time it gets translated.
* You cannot use the option to display the 'Automatic translation from ...' 
text line at the bottom of translated DIVs, as this will be included in the 
next translation and therefore appear twice!
* Re-translations into the same language will no longer be instant, as all 
content must be sent to Google for re-translation.

Unfortunately it is not possible to fix these issues without making major 
changes to the current script.

Hope this helps - please let me know how you get on.

Original comment by phathway@gmail.com on 16 May 2011 at 12:04

GoogleCodeExporter commented 8 years ago
Hi,

Thanks for the quick reply.

Cant we add some logic so that contains of only that AjaxDiv (Div hosting
Ajax contains) will be removed from the cache and will be
 resented Google every time.

Original comment by schinsammy@gmail.com on 16 May 2011 at 6:17

GoogleCodeExporter commented 8 years ago
Hi,

Any Updates on this

Original comment by schinsammy@gmail.com on 18 May 2011 at 7:27

GoogleCodeExporter commented 8 years ago
Sorry for the delay...

I think something like that might be possible. To say for sure though, I need 
to know a bit more about what you are trying to achieve:

1. What kind of content is within the DIV? Does your AJAX script replace the 
entire contents of it with new HTML code? Or does it add new content to it, or 
change/remove just some of the content within it?
2. Is this DIV specifically named within the GL_classIds or GL_classNames 
arrays at the top of this translation script? Or is it contained within another 
element that is included there?
3. Can you provide an example page that demonstrates your script working? This 
isn't essential, but would be helpful...
4. Are you comfortable using JavaScript?

If you can let me know the answers to these questions, I'll see if I can come 
up with something... Many thanks!

Original comment by phathway@gmail.com on 18 May 2011 at 8:41

GoogleCodeExporter commented 8 years ago
Please find the Answer bellow.

On Thu, May 19, 2011 at 2:11 AM,
<multi-language-translation@googlecode.com>wrote:

   Yes I am replacing the Entire contains of the Div with the new content.

   Yes Id of this Div is Added in the Class Ids.

 3. Can you provide an example page that demonstrates your script working?

   sorry I cant provide the live example as i am currently using it in local
environment.

   Yes I am quite comfortable with java script.

Original comment by schinsammy@gmail.com on 19 May 2011 at 5:46

GoogleCodeExporter commented 8 years ago
Excellent - those were exactly the answers I was hoping for :)

I've created a new function that will clear/rebuild the part of the cache that 
includes the content in the DIV that was updated by your AJAX script. Please 
see the attached file. You can either copy all the contents into the 
'translate.js' file, or just include this file in your page HTML:

<script type="text/javascript" src="update-div.js"></script>

Every time your AJAX script has updated the div content, you need to make sure 
you run this function:

updateDivContents(elementId, newContent, reTranslate);

* elementId is the ID of the DIV that was updated by your AJAX script.
* newContent is the new content that was retrieved by your AJAX script, which 
replaces the old content inside the DIV. 
* reTranslated can be set to true or false. If true, the page will 
automatically be re-translated immediately, taking into account the new DIV 
content. If false, the content will not be re-translated until the user changes 
the current language.

[Note: this function should only be run after the original cache has been built 
- i.e. *after* the original page has loaded.]

--

The new function resolves the 2 most serious issues I mentioned originally  - 
i.e. translation quality shouldn't degrade every time your DIV gets updated, 
and it is now possible to include the 'Automatic translation from ...' text at 
the bottom without it being shown twice (or more).

All page content is still resubmitted to Google after the DIV has been updated 
though, which will be slightly slower than if just the new content were 
submitted. This is due to the way content is cached currently, and 
unfortunately this can't be changed easily. At some point I do plan to update 
the original script to cache content more intelligently (which will make 
translations quicker and resolve this issue as well), but this won't be 
happening any time soon... The script should now be usable though :)

--

Please let me know whether this all works properly, as well as if you need any 
more help or discover any further issues. Many thanks for drawing this problem 
to my attention!

Original comment by phathway@gmail.com on 20 May 2011 at 12:56

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks Dude,

This was exactly what i was looking for.
Script worked for me with minor changes.

I have changed the script to accept the array of Ids and divContents
As i want to send multiple Divs

Thanks!
I appreciate the help provided.

Regards
SchinSammy

Original comment by schinsammy@gmail.com on 20 May 2011 at 8:15

Attachments:

GoogleCodeExporter commented 8 years ago
Hi 

Anather issu that i have faced is that
"After translation font size and spaces between line is increased"
May be because of difference in font in different lenguage.

Can we have same standered font applied to text after translation so that line 
spaces are same in native languages

This is just a suggessstion

Thanks
Siddesh

Original comment by schinsammy@gmail.com on 20 May 2011 at 10:45

GoogleCodeExporter commented 8 years ago
Many thanks for this :)

I'm glad that the new script worked for you as expected... I plan to officially 
release it as an add-on to the standard script (incorporating your changes, 
along with a couple of extra ideas of my own). Although the main translation 
script was not originally designed with dynamically updated page content in 
mind, I agree that it should be able to cope with that, and this new script 
helps achieve it. I have therefore really appreciated your input on this matter.

With regard to the font size and line spacing changing after translation, I 
think this is imposed by web browsers and/or by Google? So I'm not sure if this 
is something that can be changed? It should only affect some languages?

Thanks again!

Original comment by phathway@gmail.com on 24 May 2011 at 9:08

GoogleCodeExporter commented 8 years ago
Hi,

Its my pleasure.

I have a suggestion.
I have a forum on which user post there comments and requirements.
My requirement is to filter the comments posted by users to find out
any porn/illegal
words posted.

Can we extended the Language API to this task?
Do we have any other Google API which i can use.

Please suggest the appropriate solution.

Original comment by schinsammy@gmail.com on 25 May 2011 at 6:33

GoogleCodeExporter commented 8 years ago
I'm afraid this seems to be beyond the scope of this script. As far as I am 
aware, the Google Language API is not capable of achieving that, and I don't 
know of any other Google APIs that do this either.

The best advice I can give is to do a general web search and see if you can 
find something that does what you are looking for... Sorry I can't be more 
helpful.

Original comment by phathway@gmail.com on 25 May 2011 at 8:51

GoogleCodeExporter commented 8 years ago
No issues.

Original comment by schinsammy@gmail.com on 26 May 2011 at 6:02