Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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 06:28 PM.


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