BeBot - An Anarchy Online and Age Of Conan chat automaton
Archive => Anarchy Online Archive => 0.2.x Custom/Unofficial Modules => Topic started by: lulifuz on June 10, 2006, 08:00:38 pm
-
Hi there,
this is an in-game translation module which translates text to German. It uses Altavistas Bablefish for translation.
This is just a quick hack with some code that I grabbed from this site: http://vivaolinux.com.br/scripts/verScript.php?codigo=512 (http://vivaolinux.com.br/scripts/verScript.php?codigo=512)
This was made upon a request from some org member with limited English skills.
I am in no way a php-programmer so I am happy I got that far.
But I think there are more people out there that would be happy to have a in-game translation tool.
So maybe some on of the bebot wizards can come up with a real solution?
In the original code there has even been the possibility to chose the language. That could be also very usefull I suppose.
However, just thought this is a good idea that should not get lost.
Greets,
lulifuz
<?
/*
* De.php - translates english text to german.
*
* a module for
* BeBot - An Anarchy Online Chat Automaton
*
*/
$de = new De($bot);
$commands["tell"]["de"] = &$de;
$commands["pgmsg"]["de"] = &$de;
$commands["gc"]["de"] = &$de;
/*
The Class itself...
*/
class De
{
var $bot;
/*
Constructor:
Hands over a referance to the "Bot" class.
*/
function De (&$bot)
{
$this -> bot = &$bot;
}
/*
This gets called on a tell with the command
*/
function tell($name, $msg)
{
if (preg_match("/^" . $this -> bot -> commpre . "de (.+)$/i", $msg, $info))
$this -> bot -> send_tell($name, $this -> make_reply($info[1]));
else
$this -> bot -> send_help($name);
}
/*
This gets called on a msg in the privgroup with the command
*/
function pgmsg($name, $msg)
{
if (preg_match("/^" . $this -> bot -> commpre . "de (.+)$/i", $msg, $info))
$this -> bot -> send_pgroup($this -> make_reply($info[1]));
}
/*
This gets called on a msg in the guildchat with the command
*/
function gc($name, $msg)
{
if (preg_match("/^" . $this -> bot -> commpre . "de (.+)$/i", $msg, $info))
$this -> bot -> send_gc($this -> make_reply($info[1]));
}
function make_reply($inmsg)
{
return $this -> traduzir($inmsg, "en_de");
}
function strtoupper_utf8($string)
{
$string=utf8_decode($string);
$string=strtoupper($string);
/* $string=utf8_encode($string); */
return $string;
}
/*
Programado por F?io Berbert de Paula <[email protected]>
http://www.vivaolinux.com.br
Script usado para traduzir texto em diversos idiomas usando a engine
do babelfish.altavista.com como fonte de pesquisa.
Rio de Janeiro, 29/07/2002
*/
// fun?o usada para traduzir um texto
function traduzir($urltext,$lp) {
// defini?o de vari?eis
$host = 'babelfish.altavista.com';
$vars = "doit=$DOIT&tt=$TT&urltext=" . urlencode(utf8_encode($urltext)) . "&lp=$lp";
$url = "/tr?$vars";
// efetuando conex? com o babelfish
$fp = fsockopen ($host, 80, $errno, $errstr, 30);
if (!$fp) {
$traducao = "Fehler: $host: $errstr ($errno)<br>\n";
exit;
} else {
// Accept-Language: en
// Accept-Charset: iso-8859-1,*,utf-8
$addinfo .= "Accept-Language: en\r\nAccept-Charset: iso-8859-1,*,utf-8\r\n";
fputs ($fp, "GET $url HTTP/1.1\r\nHost: $host\r\n$addinfo\r\n");
while (!feof($fp)) {
$html .= fgets ($fp,128);
}
fclose ($fp);
}
// removendo quebras de linhas do resultado
$html = ereg_replace("\n"," ",$html);
// capturando o texto rtaduzido
ereg("name=\"q\" value=(.*)>",$html,$saida);
$traducao = $saida[1];
$traducao = ereg_replace(">.*$","",$traducao);
// decodificar a string
$traducao = utf8_decode($traducao);
return($traducao);
}
}
?>
-
Hmm, works fine except sometimes it returns nothing but a clear line. :-X
-
Hi there,
you are right, got this also sometimes.
Could have several reasons as I am not doing any error checking ;-)
May be bablefish is not reachable or the word can not be translated.
Hm, if I find some time I gonna try some things out, maybe I can fix it.
Greetings,
lulifuz
-
Wow nice work :D Now only if babelfish wasnt nerfed..