Open Bug 195670 Opened 17 years ago Updated 10 years ago

Language translator for Chatzilla

Categories

(Other Applications :: ChatZilla, enhancement)

enhancement
Not set

Tracking

(Not tracked)

People

(Reporter: jstark, Assigned: rginda)

Details

Attachments

(1 file, 3 obsolete files)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3b) Gecko/20030210
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3b) Gecko/20030210

This patch adds realtime language translation to Chatzilla by making behind the
seens queries to Google's language tools.  You can select the desired language
translation on a per user basis by right clicking in the "nick list" and
selecting a language option from the new "Translation" sub-menu.  After
selecting a language, when data arrives fom that nickname, Chatzilla will
perform a translation on the message data and append the rusults to the message.

This is very much a proof of concept hack and I've only done minimal testing on
Linux and Windows.  One of the major limitations is the use of syncronis
XMLHttpRequest queries that introduce a bit of lag into the session.  I have
found it to be useable for my purposes though.

The modified chatzilla.jar file can be found here:

http://portal.deximer.org/Members/jeremy/chatzilla.jar/file_view

I wrapped all of my source modifications in comment tags: /* JLS */

Kind Regards,
Jeremy

Reproducible: Always

Steps to Reproduce:
1.
2.
3.
To install:
  * put this file (cz.patch) in $MOZILLA_HOME/chrom/content/chatzilla
  * execute: patch < cz.patch
To install:
  * put this file (cz.patch) in $MOZILLA_HOME/chrome/content/chatzilla
  * execute: patch < cz.patch

This patch corrects a few bugs in the previous patch that made it impossible to
turn the translator off.  The option "None" from the translation menu will now
disable the translator for the selected user.

This patch is based on the Mozilla 1.3b release.
Attachment #116124 - Attachment is obsolete: true
I have bumped into two obsticles that I think if resolved would make the
translator usefull at a basic level:

1. International characters are getting mangled
   XMLHttpRequest is not handling international characters properly.  I have
tried setting Content headers but I can't seem to get the magic to work.  It
could be the way I'm handling the string or other factors I have yet to identify.

2. Asyncronis XMLHttpRequests lack state
   It seems that the object available within the "onload" callback funtion is
not the same object that opened the async request.  I tried setting a property
on the XMLHttpRequest object before calling .open(), e.g.:

theObject = new XMLHttpRequest();
theObject.onload = translationReceived;
theObject.TD = msgTD;
theObject.open("...

   When the onload callback is fired, the .TD property is not available.  The
problem is that I can not be sure of the order in which the asyn requests will
return so there needs to be some data associated with each object.  I can't get
the data to stick between .open() and the callback.

   If I can solve this than hopefully the request object can just have a TD
element associated with it and update the history window when a translation is
received.

Cheers,
Jeremy
I'm not sure about (1) at this point, but (2) can be solved by "capturing" the
object you are interested in the scope of your onload handler, like...

function request(td)
{
   function onload(e)
   {
        dd("td is " + td);
   }

   xmlrequest = new XMLHTTPRequest();
   xmlrequest.onload = onload;
   ...
}

When the nested onload function is called, all of the local variables defined in
the containing scope will be available.

Also, please have a look at http://www.hacksrus.com/~ginda/chatzilla/pedant.html
for the ground rules.  I'll take a closer look at your patch as soon as I can.
Things added:

  1. Calls to Google's translator are now asyncronis.  The non-translated text
  will be displayed immidiatly.  when the translation arrives it will be back
  filled into the appropriate chat history line.

  2. International characters are no longer mangled

  3. The code now conforms to Chatzilla's coding style guidelines.
Attachment #116194 - Attachment is obsolete: true
Status: UNCONFIRMED → NEW
Ever confirmed: true
A few comments...

No need for the /* JLS */ comments.  The diffs make it clear what you've
changed, and CVS blame will take care of it post check-in.


There is no provision to translate *to* a non-english language.  ChatZilla has a
number of users who don't speak english as a first language.


I'd rather see a single translate function that takes the source (and maybe
destination) address as parameters then a set of functions that only differ by a
single string.  I'd suggest the function be named /translate instead of /lang. 
The latter might be easily confused with /charset -like functionality.


Command functions start with onInput, by convention.  It's not the best
convention, I know, but it hasn't been broken yet, AFAIK.


A way to translate an entire channel from one language to another would be nice.
 I'd actually assume this would be the most common use, where I walk into, say
#mozillazine-jp, and need everything translated from Japanese to English.


An outbound translation might be nice too, but could be beyond the scope of what
you're doing here.


One thing missing from pedant.html is the paren style, which looks like...

  foo(a, b); or sometimes foo (a, b); but the former is preffered.  except for 
  |if| satements which *always* have a space before the paren.

  foo ( a, b ); and/or foo( a, b ); aren't used.

I'll add this to pedant.html for future reference.


+ function translate( lang, message, msgTD )
+ {
+     netscape.security.PrivilegeManager.enablePrivilege(
+         "UniversalBrowserRead" );

You don't need to request privileges from chrome: files.  They already have
access to everything.

+     function onLoad(e)
+     {
+         var translation =
+             google.responseText.match( /PHYSICAL>(.[^<]+)<\/textarea>/ );
+         e.originalTarget.TD.firstChild.firstChild.data +=
+             " [" + translation[1] + "]"; 
+         return;
+     }

You probably want to test |if (translation)|, in case google sends back
something unexpected.  Also, the return; is not needed.

+     catch (e)
+     {
+         return;
+     }

Ya!  Never ignore exceptions without a good reason, and a comment.  What
exceptions might be thrown here, why why don't they matter?

+ 
+     return;
+ }

return; not needed here.

+         google.open("GET", "http://translate.google.com/translate_t?text=" +
+             message + "&langpair=" + lang +
+ 	    "&hl=en&ie=ASCII&oe=ASCII&submit=Translate", true);

those lines should line up with the " in "GET".

+         transLang = eval( "sourceObj.parent.users." +
+ 	    sourceObj.nick + ".lang" );

That's an egregious use of eval().  This would be better written as
sourceObj.parent.users[sourceObj.nick].lang.  In JavaScript, the square bracket
syntax allows you to indirectly reference a property anywhere the . operator can
be used.  Also, the .lang property might not exist on a particular user object.
 To avoid a strict warning, test |if ("lang" in user)| first.
Product: Core → Other Applications
OS: Linux → All
Hardware: PC → All
This is a first pass at rewriting the translator as a Chatzilla plugin.

To install this new version, unzip it in your Chatzilla scripts directory.  In
UNIX that will be most likely be:
.mozilla/firefox/{profileID}/chatzilla/scripts.  On other platforms, all bets
are off.  Check with Chatzilla documentation.

Here is the list of things on my radar in order to make this plugin "complete":


1. Selection of translation languages by nick.	The old translator let you
right click on a nick and select a language to translate from.	This one
requires you edit the init.js file and plug in language pairs.	I will be
adding right click menus to do this as well as slash commands to set language
options globaly.

2. Translator rotation or some other interleaving of translation sites.  This
is to get around the throtles these sites now seem to enforce.	I'll be
checking return values and switching to alternat translation sites on failure,
things like that.

3. I'd like to have little graphical links to translators in the translated
line so that you can click on them and get a translation from a different site
if the one you got was not very good.

4. Add some color to the translated text.

Kind Regards,
Jeremy
Attachment #116351 - Attachment is obsolete: true
QA Contact: samuel → chatzilla
Hi

it's a pity that this useful and smart plugin had been abandoned ,I would like to complete this

I have talked about this in #chatzilla mainly with Gryllida and other 

and we were thinking about developping a new plugin that will translate in paragraph added near the original sentences like in mibbit 
http://www.mibbit.com/chat/

for example 

John: hello [hola]
Kate: nice to meet you [ encantado de conocerte ]

and then it could be cool if could be added even Firevox

http://www.firevox.clcworld.net/

 to loud that translation in brackets in paragraphs

this extension would consist of a script which will translate each single phrase of the chat through some websites (i.e., google translator, wordlingo, etc.). it will show the translation (to the chat and/or only to those who have installed the script , so with these two different options). that could allow for different translations with each individual nickname in the chat. translations should appear (between brackets) beside the original phrases of the chat, with a different color.
the most important thing is that the script should integrate with text to speech (tts), draw instant translation and turn it into audio with tts present on windows. therefore any installed language (which could be selected from a drop down menu) will let read only the translation between brackets in real time.
It should be developed as a script not with bot.

I dream this plugin ,help me to develop it 

I can even pay something if you help me to develop this 

Tell me
Hi

it's a pity that this useful and smart plugin had been abandoned ,I would like to complete this

I have talked about this in #chatzilla mainly with Gryllida and other 

and we were thinking about developping a new plugin that will translate in paragraph added near the original sentences like in mibbit 
http://www.mibbit.com/chat/

for example 

John: hello [hola]
Kate: nice to meet you [ encantado de conocerte ]

and then it could be cool if could be added even Firevox

http://www.firevox.clcworld.net/

 to loud that translation in brackets in paragraphs

this extension would consist of a script which will translate each single phrase of the chat through some websites (i.e., google translator, wordlingo, etc.). it will show the translation (to the chat and/or only to those who have installed the script , so with these two different options). that could allow for different translations with each individual nickname in the chat. translations should appear (between brackets) beside the original phrases of the chat, with a different color.
the most important thing is that the script should integrate with text to speech (tts), draw instant translation and turn it into audio with tts present on windows. therefore any installed language (which could be selected from a drop down menu) will let read only the translation between brackets in real time.
It should be developed as a script not with bot.

I dream this plugin ,help me to develop it 

I can even pay something if you help me to develop this 

Tell me
Hi Luca,

   I would like to update this script for the latest Chatzilla. I'll need to do a little research on the size of the user base for Chatzilla. It's been a long time since I have used it ad thought that maybe Chatzilla itself would be abandoned by now.

   I'm very busy the next couple weeks but could dedicate some time later in the month.

   My goal with the plugin was to have it translate from every language being used in a channel to the the users native language. I never quite achieved that but I did use it to work with a team of developers in Italy, which was why I originally wrote it. I guess once I scratched my itch I just stopped scratching :).

   One problem I ran into was that the translation services started to throttle the number of requests they would accept. I had to start round robining between services. It just became a hassle to work on but maybe there are new options now.

   R Ginda had some good ideas up the thread a bit, too.

Regards,
Jeremy
http://twpol.dyndns.org/mozilla/chatzilla/ceip/reports/live/data.html has some info on the userbase, though it's opt-in AFAIK.

Edit: More accurate data from https://addons.mozilla.org/en-US/firefox/statistics/addon/16
"Active Daily Users On Sunday, May. 30: 248,402"
In reply to comment #11:
In addition, one probably ought to add all SeaMonkey downloads to the "Daily Downloads" shown in those AMO statistics, since SeaMonkey comes with Chatzilla built-in. Of course this does not mean that every SeaMonkey user actively _uses_ Chatzilla; but in any case I'd say that "abandoned by now" is certainly no accurate description. I'm sure I'm not the only SeaMonkey user whose reaction would be "Why go shopping for another chat client when I've already got a perfectly usable one as part of my Suite?"
Hi Jeremy I am really happy to hear you
I tried to write you an email time ago but you didn't reply

I am italian too if you need something tell me ;)



I would like to develop that addon together with text to speech options 

so I have set up a forum to bring there all developers that could help me to realize this

http://www.yodahack.50gigs.net/index.php

PLEASE join there and help me 
if you don't want to register you can post as guest too 
I hope to see you all there :)
Bye
You need to log in before you can comment on or make changes to this bug.