Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Translate (https://forums.graalonline.com/forums/showthread.php?t=134257258)

fowlplay4 12-11-2009 07:16 AM

Translate
 
Was bored, and felt like doing another one of those requesturl projects of mine, would be awesome if there was post variable support.

The translate class (also works on the client-side):

PHP Code:

function onCreated() {
  
// For server's running on the 64-bit NPC-Server (Era, Zodiac, etc.)
  
addDNSEntry("ajax.googleapis.com""72.14.213.95");
}

function 
translate(inital, final, message) {
  
// Determine URL
  
this.requests++;
  
temp.site "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&langpair=";
  
temp.lang urlencode(inital "|" @ final);
  
temp.url  temp.site temp.lang "&q=" message "&id=" this.requests;
  
// Request URL
  
temp.req requesturl(temp.url);
  
temp.data this.catchevent(temp.req"onReceiveData""onTranslation");
  
// Return Request ID
  
return this.requests;
}

function 
onTranslation(obj) {
  
// Parse Data
  
temp.request obj.url.substring(obj.url.pos("&id=")+4);
  
temp.trans obj.fulldata.substring("{'responseData': {'translatedText':'".length());
  
temp.trans temp.trans.substring(0temp.trans.pos("}, \"responseDetails\": null,")-1);
  
// Handle Translation
  
handleTranslation(temp.requesttemp.trans);


Credit to Programmer for the languages enum.

PHP Code:

enum Languages 

 
Afrikaans "af"
 
Albanian "sq"
 
Amharic "am"
 
Arabic "ar"
 
Armenian "hy"
 
Azerbaijani "az"
 
Basque "eu"
 
Belarusian "be"
 
Bengali "bn"
 
Bihari "bh"
 
Bulgarian "bg"
 
Burmese "my"
 
Catalan "ca"
 
Cherokee "chr"
 
Chinese "zh"
 
Chinese_Simplified "zh-CN"
 
Chinese_Traditional "zh-TW"
 
Croation "hr"
 
Czech "cs"
 
Danish "da"
 
Dhivehi "dv"
 
Dutch "nl"
 
English "en"
 
Esperanto "eo"
 
Estonian "et"
 
Filipino "tl"
 
Finnish "fi"
 
French "fr"
 
Galician "gl"
 
Gregorian "ka"
 
German "de"
 
Greek "el"
 
Guarani "gn"
 
Gujarati "gu"
 
Hebrew "iw"
 
Hindi "hi"
 
Hungarian "hu"
 
Icelandic "is"
 
Indonesian "id"
 
Inuktitut "iu"
 
Italian "it"
 
Japanese "ja"
 
Kannada "kn"
 
Kazakh "kk"
 
Khmer "km"
 
Korean "ko"
 
Kurdish "ku"
 
Kyrgyz "ky"
 
Laothian "lo"
 
Latvian "lv"
 
Lithuanian "lt"
 
Macedonian "mk"
 
Malay "ms"
 
Malayalam "ml"
 
Maltese "mt"
 
Marathi "mr"
 
Mongolian "mn"
 
Nepali "ne"
 
Norwegian "no"
 
Oriya "or"
 
Pashto "ps"
 
Persian "fa"
 
Polish "pl"
 
Portuguese "pt-PT"
 
Punjabi "pa"
 
Romanian "ro"
 
Russian "ru"
 
Sanskrit "sa"
 
Serbian "sr"
 
Sindhi "sd"
 
Sinhalese "si"
 
Slovak "sk"
 
Slovenian "sl"
 
Spanish "es"
 
Swahili "sw"
 
Swedish "sv"
 
Tajik "tg"
 
Tamil "ta"
 
Tagalog "tl"
 
Telugu "te"
 
Thai "th"
 
Tibetan "bo"
 
Turkish "tr"
 
Ukrainian "uk"
 
Urdu "ur"
 
Uzbek "uz"
 
Uighur "ug"
 
Vietnamese "vi" 
}; 

Usage:

PHP Code:

function onCreated() {
  
// Inherit Translation Functionality
  
join("translate");
  
// Translate
  
temp.req translate("en""es""hello");
  
// Setup
  
setupTranslation(temp.req);
}

function 
setupTranslation(requestid) {
  
// If you wanted to adapt to this an active player chat translator
  // You could set the player's chat to the requestid like so:
  // this.("request_" @ requestid) = acct;
  // Provided you added an acct parameter.
}

function 
handleTranslation(requestidtranslation) {
  
// This is automatically called when the request returns
  // Referring back to the player translator 
  // You could use some code to change the player stored in the request
  // to the translation.
  
echo(translation);


But anyway here's some example usage I did on my RC:

PHP Code:

JerretNPCtranslate(en,es,hello)
hola 


cbk1994 12-11-2009 01:47 PM

Heh, that's pretty cool. Probably quite useless, but really cool.

TSAdmin 12-11-2009 02:13 PM

Quote:

Originally Posted by cbk1994 (Post 1543701)
Heh, that's pretty cool. Probably quite useless, but really cool.

I wouldn't say it's useless. I can think of one good use, provided messing around with the scripts a little:

Another step toward a user-friendly display, with the ability to change everything in their display (GUI, classes with text, etc etc) to their own language. Create a display with something like convertUserLang(en, player.lang, "Text to display"); or something of the sort. If they haven't selected a language, default would be English naturally.

coreys 12-11-2009 03:42 PM

Nice use of Google APIs! No one makes 'em like Google. (Hoping to get an internship there myself, with a little help from a guy I know how works there)

In any case, nice script! I intend on using this. :)

I am curious about the addDNSEntry function, however. I was gone for a year so it seems there's a lot I missed out on, there's a 64-bit server, and why the need for that?

fowlplay4 12-11-2009 05:53 PM

Quote:

Originally Posted by coreys (Post 1543709)
I am curious about the addDNSEntry function, however. I was gone for a year so it seems there's a lot I missed out on, there's a 64-bit server, and why the need for that?

There's a bug, and you need to add the dns entry or requesturl doesn't work.

On Zodiac RC we got /npc german, french, etc. was quite fun to play around with.

Admins 12-11-2009 06:51 PM

Quote:

Originally Posted by coreys (Post 1543709)
I am curious about the addDNSEntry function, however. I was gone for a year so it seems there's a lot I missed out on, there's a 64-bit server, and why the need for that?

The graal servers now run on 64 bit machines & Linuxes, but we have not tested the 64 bit version of the npcserver a lot yet (want to avoid npcs being deleted or people losing items). That's why the DNS lookup is bugged right now and you need to use addDNSEntry(host, ip) if you want to use TSocket or requesturl on serverside.

coreys 12-11-2009 07:36 PM

Ah, cool. It will be nice to have every server running in 64-bit in the future.

tempandrew 12-11-2009 08:36 PM

Quote:

Originally Posted by cbk1994 (Post 1543701)
Heh, that's pretty cool. Probably quite useless, but really cool.

If this can be successfully linked to every aspect of the server, it'd be really useful for non-english speaking players to be able to actually know how to do things, and what everything is.

Quote:

Originally Posted by Stefan (Post 1543728)
The graal servers now run on 64 bit machines & Linuxes, but we have not tested the 64 bit version of the npcserver a lot yet (want to avoid npcs being deleted or people losing items). That's why the DNS lookup is bugged right now and you need to use addDNSEntry(host, ip) if you want to use TSocket or requesturl on serverside.

THAT is awesome, it'd be useful for Graal to utilize 64-Bit processors, which have just about become the norm now-a-days.

DustyPorViva 12-11-2009 08:48 PM

It might not be useful for full translation, but it could be helpful for simple-worded translations like menus and such.

Switch 12-11-2009 09:48 PM

Atlantis :megaeek:

Admins 12-12-2009 12:19 AM

Quote:

Originally Posted by tempandrew (Post 1543749)
THAT is awesome, it'd be useful for Graal to utilize 64-Bit processors, which have just about become the norm now-a-days.

Mac v6 already supports 64 bit (universal binary) :)

Quote:

Originally Posted by DustyPorViva (Post 1543754)
It might not be useful for full translation, but it could be helpful for simple-worded translations like menus and such.

May be there could be some auto-po file generation (extracts _("word") from all scripts and then gets the translation from google).

coreys 12-12-2009 02:15 AM

Quote:

Originally Posted by DustyPorViva (Post 1543754)
It might not be useful for full translation, but it could be helpful for simple-worded translations like menus and such.

Google's translation software is actually pretty great. There's grammatical errors here and there, but definitely suitable for widespread use.


All times are GMT +2. The time now is 08:22 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.