Author Topic: Anyone ever tried in-game translation of real world languages?  (Read 801 times)

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0


               

I was looking around for free translation engines.


Google Translate offers x amount for free, but then you have to pay for extra, so it wasn't really a candidate.


 


I heard of something called Apertium, which is basically Machine Translation - using Language Pairs / Key lookups.


 


I wrote a wrapper for this in Java, currently calling the online free API.


I can then expose this to nwscript.



String spanish = Apertium.getTranslation("eng", "spa","Hello my name is Samuel");
 


 


Sending 'GET' request to URL : https://www.apertium... name is Samuel

Response Code : 200

{"responseDetails": null, "responseData": {"translatedText": "Hola Mi nombre es Samuel"}, "responseStatus": 200}



 

It seems pretty accurate with the tests I've done. Its quite responsive, returning the translated test in less than a second. The translation engine is also available for download, so you could even host it locally to the nwserver and just upload the translation keys yourself.

 

Would be interesting to know if anyone has ever tries implementing in-game translation to facilitate cross-cultural gaming.

 

 

Note - just tested installing Apertium locally.

 



echo "Hello my name is Jonathan" | apertium en-es


On linux console :



Hola Mi nombre es Jonathan



 

Still quite fast.

Would imagine this could be useful for communities that are heavily Spanish and English mix.

It probably won't be a perfect translation, but it might be a start.

 

Tried a more complex request

 



 

echo "Hello my name is Jonathan, Can I join your party, I am a level 33 sorcerer" | apertium en-es


Hola Mi nombre es Jonathan , Puede  uno vuestro partido,  soy un nivel  33 *sorcerer

 

 

 echo "The boss cannot be killed by conventional weapons, you must bless your weapon with holy magic, otherwise the boss will heal every time you strike him." | apertium en-es

 

El jefe no puede ser matado por armas convencionales,  tienes que bendecir vuestra arma con magia santa, *otherwise el jefe se curará cada vez  le golpeas.

 

 echo "You take the dragon on the left, I will take the Demons on the right. Let me know if you need potions, I have many." | apertium en-es

 

 Tomas el dragón en el izquierdo,  tomaré los Demonios en el correctos. Dejado me saber si  necesitas pociones,  tengo muchos.

 




 

The * seems to indicate phrases / words it has trouble with.

 

I think something like this could be tweaked and worked into an onPlayerChat hook.

Eg: Player1 is English

      Player2 is Spanish

 

When they speak : If their language's don't match, then the system converts to the appropriate language, and the translation appears as 'SendMessageToPC()' text.

 

 

Back to english translation:

 



echo "Tomas el dragón en el izquierdo" | apertium es-en

You take the dragon in the left

 



               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Anyone ever tried in-game translation of real world languages?
« Reply #1 on: April 18, 2016, 02:22:41 pm »


               

In case anyone is interested in the performance of Apertium.


The lookup - even when local to the server, can be a little sluggish.


However, with an appropriate caching system, this is reduced significantly.


 


Running this java code on ubuntu, to simulate NWScript calls to it.



public static void main(String[] args){
Date dStart = new Date();
for(int i=0;i<=100000;i++){
Apertium.getTranslation("en", "es",randomPhrase(), true);
//System.out.println(spanish);
}
Date dEnd = new Date();
long time = dEnd.getTime()-dStart.getTime();
System.out.println("Took "+(time/1000)+" seconds to complete");
 
}
 


randomPhrase:



public static String randomPhrase(){
int i = new Random().nextInt(10);
String strReturn = "";
switch(i){
case 1:
strReturn = "My name is Jonathan";
break;
case 2:
strReturn = "Can I join your party";
break;
 
case 3:
strReturn = "Where are you from?";
break;
case 4:
strReturn = "Oh, I had no idea you were spanish?!";
break;
case 5:
strReturn = "Do you know Juan Pablo Raba from Agents of Shield? I think he is well tasty.";
break;
case 6:
strReturn = "I may be a little obsessed with him.";
break;
case 7:
strReturn = "I just wish he would notice me!";
break;
case 8:
strReturn = "He won't respond to my twitter or facebook posts. Its like he doesn't even see me.";
break;
case 9:
strReturn = "Sometimes it makes me upset.";
break;
case 10:
strReturn = "My therapist says I should try to not think about him.";
break;
}
return strReturn;
}
 


10,000 calls took:


 



java -cp org.nwnx.nwnx2.jvm.jar org.test.unitTester

Took 11 seconds to complete


 

Because I implemented caching - using the translation texts hashCode();

 



private static Hashtable<Integer,String> cache = new Hashtable<Integer,String>();
 
//https://www.apertium.org/apy/translate?langpair=eng|spa&q=Hello+my+name+is+Jonathan
@SuppressWarnings("deprecation")
public static String getTranslation(String from, String to, String strQuery, boolean local){
String s = "";
int hash = strQuery.hashCode();
if(cache.containsKey(hash)){
return cache.get(hash);
}
if(local){
try {
String command = "apertium";
String arg = from+"-"+to;
s = Command.exec(command,arg,strQuery);
cache.put(hash, s);
} catch (IOException | InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return s;
}
strQuery = URLEncoder.encode(strQuery);
String url = "https://www.apertium.org/apy/translate?langpair="+from+"|"+to+"&q="+strQuery;
try {
TranslationResponse t = sendGet(url);
s = t.getResponseData().getTranslatedText();
return s;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
 
}

 

 

The only other way I can think of to prevent the translation from holding up server processing too much, is to use background threads in java, and then execute SpeakString() from that background thread.

 


               
               

               
            

Legacy_dunahan_schwerterkueste_de

  • Jr. Member
  • **
  • Posts: 66
  • Karma: +0/-0
Anyone ever tried in-game translation of real world languages?
« Reply #2 on: April 24, 2016, 08:04:59 am »


               

Hm, on the first look, this seems a quite interesting use for letting all other players of the world playing with each others on every server that has this functions installed. Looking forward for this '<img'>