Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-11-2009, 07:16 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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 
__________________
Quote:

Last edited by fowlplay4; 12-11-2009 at 07:48 PM..
Reply With Quote
  #2  
Old 12-11-2009, 01:47 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Heh, that's pretty cool. Probably quite useless, but really cool.
__________________
Reply With Quote
  #3  
Old 12-11-2009, 02:13 PM
TSAdmin TSAdmin is offline
Forum Moderator
TSAdmin's Avatar
Join Date: Aug 2006
Location: Australia
Posts: 1,980
TSAdmin has much to be proud ofTSAdmin has much to be proud ofTSAdmin has much to be proud ofTSAdmin has much to be proud ofTSAdmin has much to be proud ofTSAdmin has much to be proud of
Quote:
Originally Posted by cbk1994 View Post
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.
__________________
TSAdmin (Forum Moderator)
Welcome to the Official GraalOnline Forums! Where sharing an opinion may be seen as a declaration of war!
------------------------
· User Agreement · Code of Conduct · Forum Rules ·
· Graal Support · Administrative Contacts ·
Reply With Quote
  #4  
Old 12-11-2009, 03:42 PM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
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?
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #5  
Old 12-11-2009, 05:53 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by coreys View Post
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.
__________________
Quote:
Reply With Quote
  #6  
Old 12-11-2009, 06:51 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Quote:
Originally Posted by coreys View Post
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.
Reply With Quote
  #7  
Old 12-11-2009, 07:36 PM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Ah, cool. It will be nice to have every server running in 64-bit in the future.
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #8  
Old 12-11-2009, 08:36 PM
tempandrew tempandrew is offline
Registered User
Join Date: May 2005
Posts: 98
tempandrew is on a distinguished road
Quote:
Originally Posted by cbk1994 View Post
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 View Post
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.
Reply With Quote
  #9  
Old 12-11-2009, 08:48 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
It might not be useful for full translation, but it could be helpful for simple-worded translations like menus and such.
Reply With Quote
  #10  
Old 12-11-2009, 09:48 PM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Atlantis
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #11  
Old 12-12-2009, 12:19 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Quote:
Originally Posted by tempandrew View Post
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 View Post
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).
Reply With Quote
  #12  
Old 12-12-2009, 02:15 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Quote:
Originally Posted by DustyPorViva View Post
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.
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:00 PM.


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