2
Donate to the B3 fund!

"even a small donation helps!"
Donate with PayPal!
Most of the plugins here are made by B3 users and the authors may not visit frequently. If you need support for plugins or if questions remain unanswered, you will have to contact the author directly. Read the full Support Disclaimer here

NOTE: Do not attach plugins to your forumtopics! Attachements are periodically removed by maintenance tasks. Upload your plugins to our Downloads section instead!

Author Topic: Translators plugin  (Read 15961 times)

Offline SvaRoX

  • Jr. Member
  • **
  • Posts: 10
Translators plugin
« on: August 26, 2010, 12:02:04 PM »
Description:
This plugin allows players to translate text on the chat without even leaving their favorite game server. It's dedicated to people who are not confident with foreign languages, who don't want to lose time into translation to communicate or those who just want to have fun with foreign friends.

Features:
- translates text from and to any language supported by Google Translate.
- automatic chat translation. If a chat line is detected to be written in a "foreign" language, the text is translated and dislplayed.



Commands:
- !trans [src lang|dest lang] <sentence> : translates a sentence (use @trans to make the translation available to everyone).
- !translast : translates the latest available sentence from the chat.
- !transauto : enables/disables automatic translation feature.
- !transversion : displays plugin version.

How to use !trans:
The source language parameter is optional and should be used if language auto-detection fails. The destination language parameter is optional, use it if you don't want to translate into the default language.
- example 1, language auto-detection, default destination language :
!trans Sentence to translate
- example 2, language auto-detection, given destination langyage :
!trans |nl Sentence to translate
- example 3, given source language, default destination language :
!trans fr| Phrase a traduire
- example 4, given source and destination languages :
!trans fr|de Phrase a traduire

Installation:
- copy the directory "xgoogle" into your b3 root directory.
- copy the file "xjson.py" into your b3 root directory (optional if you use geowelcome plugin).
- copy the file translators.py into b3/extplugins.
- copy the file translators.xml into b3/extplugins/conf.
- add the following line into the plugins section in b3.xml : <plugin name="translators" config="@b3/extplugins/conf/translators.xml"/>

Configuration file:
- settings/autotranslation : activates automatic translation at startup.
- settings/autothreshold : sets the minimum sentence size required to translate it automatically (also used by !translast).
- settings/translatecmd : if set to 1, also translates chat lines starting with a B3 command.
- settings/defaultsrclang : sets default source language (optional).
- settings/defaultdestlang : sets default destination language.

Notes:
- translations may be inaccurate, use it at your own risk.
- for a list of available languages see http://translate.google.com and http://www.google.com/cse/docs/resultsxml.html#countryCodes for country codes.
- special characters like accented letters or cyrillic are not displayed.
- the plugin name is Translators, with a final 's'.
- keep in mind that this plugin produces additional network traffic to get the results from Google Translate.
- the translation function can be used in other plugins. Just load the Translators plugin first :
Code: [Select]
     self._translators = self.console.getPlugin('translators')
     if not self._translators:
         self.debug('Could not find Translators plugin')
 Then use translate() method within try-except block :
Code: [Select]
     try:
        msg = self._translators.translate('Sentence you want to translate')
     except:
        pass
 Same language parameters as the !trans command can be set, for example translate('|es Sentence you want to translate').
- this plugin can be used as a command-line translator. Add your B3 directory path to the PYTHONPATH shell variable, then run the plugin by typing python translators.py.

Download link:
http://www.bigbrotherbot.net/forums/downloads/?sa=view;down=86

Thanks:
- Google Translate : http://translate.google.com
- xgoogle python library by Peteris Krumins: http://www.catonmat.net/blog/python-library-for-google-translate/
- DSWP community (http://www.dswp.de) and other Urban Terror players for testing.
« Last Edit: August 26, 2010, 12:07:46 PM by SvaRoX »

Offline Freelander

  • XLRstats dev.
  • Dev. Team
  • Hero Member
  • *
  • Posts: 1000
Re: Translators plugin
« Reply #1 on: August 26, 2010, 12:59:56 PM »
A very nice plugin idea. Good job!  :)

Offline misamix

  • Jr. Member
  • **
  • Posts: 44
    • UrT SRBIJA
Re: Translators plugin
« Reply #2 on: August 26, 2010, 01:31:33 PM »
very very very nice svarox

Offline ryry46d9

  • B3 Contrib/Support
  • Sr. Member
  • *
  • Posts: 337
    • Pb| clan
Re: Translators plugin
« Reply #3 on: August 27, 2010, 03:35:31 AM »
Plug-in of the year award ?

Offline xlr8or

  • [ www.xlrstats.com ]
  • Project Lead
  • Hero Member
  • *
  • Posts: 2057
    • The Art of Tactical Gaming
Re: Translators plugin
« Reply #4 on: August 27, 2010, 11:36:56 AM »
This plugin requires extra libraries to function properly. The B3 windows binaries do not hold these binaries by default. It would be great if we could include the libraries to our main B3 distribution, but it would need some reorganisation of you current plugin.

We would place the xgoogle library in: b3/lib/xgoogle/
and the xjson.py in: b3/lib/

This keeps our core code properly seperated from all included libs and makes library maintenance easier.

Please make the proper changes to the plugin and we will include the libs in our main B3 distribution.

Offline grosbedo

  • Former Dev. (senate)
  • Sr. Member
  • *****
  • Posts: 258
Re: Translators plugin
« Reply #5 on: August 27, 2010, 08:48:05 PM »
Great. Well done.

The only thing to verify is : is google ok with that ? Normally, the Google disclaimer prohibit any automatic usage of their services. So better lower down the amount of traffic to a minimum to avoid problems...
« Last Edit: August 27, 2010, 09:09:18 PM by grosbedo »

Offline grosbedo

  • Former Dev. (senate)
  • Sr. Member
  • *****
  • Posts: 258
Re: Translators plugin
« Reply #6 on: August 27, 2010, 09:59:09 PM »
I tested it on OpenArena, works well, should work for any q3a based game.

Just a suggestion : Ive noticed that !translast doesn't translate the very last chat message from all players, but the last message of the player requesting !translast. Would it be possible to switch the behaviour, so !translast effectively translate the very last message from all players ?

Offline SvaRoX

  • Jr. Member
  • **
  • Posts: 10
Re: Translators plugin
« Reply #7 on: August 28, 2010, 01:27:44 PM »
Thanks guys :)

@xlr8or:
Oops sorry I haven't tested the plugin on B3 for Windows, I will make the modifications and update it soon. Great if you add it in the distribution =) By the way, is it a rule to also use the lib directory for any third party plugins or is it just for special cases like included plugin ?

@grosbedo:
Good point mentioning the rights of using the service. In fact I also had Google's point of view in mind when I wrote the warning about traffic increase in the notes. Actually the python library is based on the Language API, which is dedicated to "semi automatic" translations from scripts, so I guess that kind of use is tolerated by Google for this service...
About !translast : it should translate anyone's chat. Did you make sure the sentence had more characters than the "autothreshold" setting ? It also doesn't translate team chat yet, I will change that in the upcoming version.

Offline grosbedo

  • Former Dev. (senate)
  • Sr. Member
  • *****
  • Posts: 258
Re: Translators plugin
« Reply #8 on: August 28, 2010, 02:30:15 PM »
Good point mentioning the rights of using the service. In fact I also had Google's point of view in mind when I wrote the warning about traffic increase in the notes. Actually the python library is based on the Language API, which is dedicated to "semi automatic" translations from scripts, so I guess that kind of use is tolerated by Google for this service...

Yes but game servers are another thing than a standard desktop application. Maybe there should be a limit, like 3 translations in a row and then you need to wait ?

For the moment I don't think this will be a problem but in the future it might be. Does your script can react if google block the access ? You know, after a certain amount of tries, Google asks for a CAPTCHA to be able to continue to use their services...

About !translast : it should translate anyone's chat. Did you make sure the sentence had more characters than the "autothreshold" setting ? It also doesn't translate team chat yet, I will change that in the upcoming version.

No, indeed, I didn't see the little mention, my bad. Thank you very much, it's working greatly now :)

Offline grosbedo

  • Former Dev. (senate)
  • Sr. Member
  • *****
  • Posts: 258
Re: Translators plugin
« Reply #9 on: August 28, 2010, 03:12:26 PM »
Just a note about ergonomy : when I use !translast, people tend to get confused and, when they try to mimic me, they type !translate.

So Ive added !translate as an alias for !trans, and !lasttrans as an alias for !translast :

Code: [Select]
    <settings name="commands">
        <set name="trans-translate">0</set>
        <set name="translast-lasttrans">0</set>
        <set name="transauto">2</set>
        <set name="transversion">20</set>
    </settings>

Offline learco

  • Full Member
  • ***
  • Posts: 124
Re: Translators plugin
« Reply #10 on: September 03, 2010, 07:39:46 PM »
this plugin doesn't work and console shut down.
it's possible i do a mistake...

here's my b3.log

Code: [Select]
100903 19:36:55	BOT    	Loading Plugin #22 translators [D:\Immagini dischi\Urban Terror\b3-1.3.3\b3-1.3.3\b3\extplugins\conf\translators.xml]
100903 19:36:55 INFO Could not load built in plugin translators (No module named translators)
100903 19:36:55 INFO trying external plugin directory : D:\Immagini dischi\Urban Terror\b3-1.3.3\b3-1.3.3\b3\extplugins
100903 19:36:55 CRITICAL Error loading plugin: No module named xgoogle.translate
Traceback (most recent call last):
  File "D:\Immagini dischi\Urban Terror\b3-1.3.3\b3-1.3.3\b3\parser.py", line 497, in loadPlugins
    pluginModule = self.pluginImport(p)
  File "D:\Immagini dischi\Urban Terror\b3-1.3.3\b3-1.3.3\b3\parser.py", line 565, in pluginImport
    return imp.load_module(name, fp, pathname, description)
  File "D:\Immagini dischi\Urban Terror\b3-1.3.3\b3-1.3.3\b3\extplugins\translators.py", line 23, in <module>
    from xgoogle.translate import Translator, TranslationError, LanguageDetector, DetectionError
ImportError: No module named xgoogle.translate
100903 19:36:55 INFO STDOUT 220
100903 19:36:55 INFO STDOUT


can anyone help me?

Offline grosbedo

  • Former Dev. (senate)
  • Sr. Member
  • *****
  • Posts: 258
Re: Translators plugin
« Reply #11 on: September 03, 2010, 11:00:14 PM »
You're missing the necessary additional libraries, or you misplaced them.

You must copy the folder xgoogle and the file xjson.py from the archive, to your b3 root folder (in the same folder as b3_run.py and setup.py). Then, you have to restart B3, and it should work.

Note : if you are using B3 on a Windows OS, you cannot use this plugin with the installer package of B3, you will have to wait for the next version of B3.

Offline learco

  • Full Member
  • ***
  • Posts: 124
Re: Translators plugin
« Reply #12 on: September 07, 2010, 12:16:17 PM »
You're missing the necessary additional libraries, or you misplaced them.

You must copy the folder xgoogle and the file xjson.py from the archive, to your b3 root folder (in the same folder as b3_run.py and setup.py). Then, you have to restart B3, and it should work.

Note : if you are using B3 on a Windows OS, you cannot use this plugin with the installer package of B3, you will have to wait for the next version of B3.

allright. very well, your suggestion is okay!
plugin with xgoogle and xjson.py now works correctly.
thank you so much!

Offline MsKiller

  • Jr. Member
  • **
  • Posts: 20
Re: Translators plugin
« Reply #13 on: September 10, 2010, 10:03:04 AM »
@SvaRoX - Really nice, even if I did not have the chance to use it yet, I'm going to install to all my servers right now, it is really a good idea !!

 ;D ;D what about going a little forward ?????

my foolish mind asked me and I do the same to you :D :P :D

do you think it could be possible to connect this plugin with a sort of geolocalization mchanism so that when activating the automatic translation it convert sentences from each other at least into the standard server's language ...


MsK

Offline grosbedo

  • Former Dev. (senate)
  • Sr. Member
  • *****
  • Posts: 258
Re: Translators plugin
« Reply #14 on: September 10, 2010, 12:09:45 PM »
do you think it could be possible to connect this plugin with a sort of geolocalization mchanism so that when activating the automatic translation it convert sentences from each other at least into the standard server's language ...

I think it should be possible and not too hard using the functions provided by the CountryFilter plugin. It would be a good idea indeed, people would get the auto translation directly in their language instead of the default English one.

 


Rate this page +1 at Google Search