Difference between revisions of "User talk:Perry Mizin"

From Second Life Wiki
Jump to navigation Jump to search
 
(34 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Bienvenid@ ==
== Bienvenid@ ==
Hola, soy Perry Mizin y este será mi humilde intento de contribucion al proyecto "[[Universal Translator|Traductor Universal de Google]]" creado por [[User:Hank Ramos|Hank Ramos]].  
Hola, soy Perry Mizin y este será mi humilde intento de contribución al proyecto "[[Universal Translator|Traductor Universal de Google]]" creado por [[User:Hank Ramos|Hank Ramos]].  


El siguiente codigo fué originalmente creado por [[User:Hank Ramos|Hank Ramos]], empezaré modificando algunas funciones a mi manera...
El siguiente código fué originálmente creado por [[User:Hank Ramos|Hank Ramos]], empezaré modificando algunas funciones a manera...
No os riais
No ós riais


== Welcome ==
== Welcome ==
Line 13: Line 13:
----
----


''Universal Translator Engine''
=== ''OK'' ===
Bueno, despues de respiñar todo lo que pude, creo que el uso de memoria y la velocidad están prácticamente igual qué en la versión original pero bueno... en la variedad está el gusto no?
Ya he probado un poco el código, y parece que funciona aunque estoy teniendo algunos problemas... Por ejemplo creo que el sistema de traduccion no funciona corréctamente, y no me refiero al sistema de traduccion de Google (en mi opinion, si no es el mejor, es uno de los mejores del mundo), sino a que aún queda mucho trabajo por hacer en el script...
 
El siguiente paso sera intentar dividir el script en dos, o si es posible en tres para repartir el uso de memoria. Tambien me gustaria probar un truco que uso a menudo para traducir páginas en un idioma que no entiendo, lo que hago es que en vez de traducir diréctamente al español, primero se traduce a inglés, y luego desde inglés al español. Parece una tontería y un gasto innecesario, pero si lo hago es porque así suelo entender mejor las traducciones.
Quiero por un lado el sistema de comunicacion y evaluacion entre traductores, y por otro el sistema de traduccion entre avatares, ¿es muy dificil? no sé ya lo veremos...
 
Well, after saving as much as I could, I think the memory usage and the speed are technically the same as in the original script, but well, in the variety is the taste, isnt it?.
I have tested a bit the code above already, and it seems to work altought i´m having some problems...
For instance i think the translation system is not working properly, and i dont mean the Google´s translation system (in my opinion, if is not the best, one of the bests), but that there is still much work to do in the script...
 
The next step will be to try to divide the script in 2, or 3 if is possible, so we can spread the memory usage. Also I would like to test a trick i use often for to translate languages that i dont understand, what I do first is to translate that language into English, and then from English to Spanish, it seems a nonsense and unnecesary waste, but if i do it is becouse so i usually understand the translations better.
I want by one part the translators communications and evaluation system, and by other the translation system between avatars, is it very difficult? I don´t know , we will see...
 
----
 
Es dificil... me está costando pero ya veremos...
Its difficult... i am struggling but we will see...
 
chu chu chu
 
----
 
De Güatemala a Güatepeor, Sin comentarios...
 
From Güatebad to Güateworse, No comments...
 
Buscando en Internet he encontrado este [http://developer.yahoo.com/search/web/V1/spellingSuggestion.html API de Yahoo] comprobador de ortografía, aunque creo que por ahora sólo soporta el lenguage inglés pero sería interesante añadirlo al proyecto
 
Searching on the web I crossed in my way with this spell checker [http://developer.yahoo.com/search/web/V1/spellingSuggestion.html Yahoo´s API] , I think that it only supports English language by now althought it would be interesting to add it to the project
 
----
 
Estoy probando el comprobador de deletreo de Yahoo aunque la verdad es que no estoy teniendo buenos resultados, parece que Google es mucho más rapido y necesito corregir antes de traducir. También estoy intentando solucionar el error que aparece con el símbolo (apostrofe) ´ en las frases con genitivo sajon traducidas al inglés y tampoco doy con la tecla... Ya que esto me está dando muchos dolores de cabeza quizás deje el proyecto en standby hasta después de navidades.
 
I am testing the Yahoo´s spell checker althought to be honest I´m not having good success, it seems Google is much faster and I need to correct before translate. Also I am triying to fix the error showed in the phrases translated to English with the saxons genitive apostrophe ´ and still triying and triying. As this is driving me nuts, maybe I will leave the project in standby until new year.
 
 
----
 
ESTO ES EL TRADUCTOR "un lío" por ahora... Necesito rehacer algunas cosas
 
THIS IS THE TRANSLATOR "mess" by now... I need to redo some things
'''THE CODE BELOW IS WORKING AND BEING TESTED'''
 
THIS IS AN ALPHA VERSION OF THE PERRYSONAL TRANSLATOR...
NOTHING MORE TO SAY
 
Menu
<lsl>
<lsl>
//Universal Translator
//Mod Made in Perry Mizin
//Version 1.9.0
//This is the interface, or menu-system of the translator.
//November 12, 2009
//Menu System
//LSL Script copyright 2006-2009 by Hank Ramos
//Copyright 2006-2009 by Hank Ramos
//Web Server Services powered by Google
//Variables
//Variables
list agentsInTranslation;
integer randomDialogChannel;
list agentsInTranslationOptions;
list requestList;
integer listenID;
integer isMaster = 1;
integer autoLanguage = TRUE;
integer enabled = FALSE;
integer showTranslation = FALSE;
integer tranObjects = TRUE;
integer lastHeartBeat;
list    languageCodes = [
"zh-CN", "zh-TW", "hr", 
"bg", "be", "ca",
"af", "sq", "ar", 
"tl", "fr", "gl",   
"fi", "en", "et",   
"cs", "da", "nl", 
"id", "ga", "it",     
"hi", "hu", "is",
"de", "el", "iw",   
"mt", "no", "fa", 
"lt", "mk", "ms", 
"ja", "ko", "lv", 
"sl", "es", "sw",
"ru", "sr", "sk",
"pl", "pt-PT", "ro",
"yi", "", "",
"uk", "vi", "cy",
"sv","th", "tr"];
list    translators;
list    sayCache;
list    sayCachePrivate;
integer priorityNumber;
integer priorityNumListenID;
integer isInitialized = FALSE;
string  options;  
//Options
//Options
//integer debug = TRUE;
integer enabled = TRUE;
integer broadcastChannel = -9999999; //note this is not the channel used by the HR Universal Translator
integer isShowTran = FALSE;
string password = "password"; //note this is not the password used to encrypt comms of the HR Universal Translator
integer tranObjects = TRUE;
integer version = 190;
//Functions
showMainMenu(key id)
{
list buttonList = [];
string dialogMsg = "Options Menu.";
if (id == llGetOwner())
{
if (enabled)
{
buttonList = (buttonList=[]) + buttonList + ["Turn OFF"];
}
else
{
buttonList = (buttonList=[]) + buttonList + ["Turn ON"];
}
if (isShowTran)
{
buttonList = (buttonList=[]) + buttonList + ["Echo OFF"];
}
else
{
buttonList = (buttonList=[]) + buttonList + ["Echo ON"];
}
buttonList = (buttonList=[]) + buttonList + ["RESET"];
dialogMsg = (dialogMsg="") + dialogMsg + "\nECHO: show translations of your chat sent to others.";
if (tranObjects)
{
buttonList = (buttonList=[]) + buttonList + ["Objects OFF"];
}
else
{
buttonList = (buttonList=[]) + buttonList + ["Objects ON"];
}
dialogMsg = (dialogMsg="") + dialogMsg + "\nOBJECTS: translate chat of scripted objects";
}
llDialog(id, dialogMsg, buttonList, randomDialogChannel);
}
processListen(string name, key id, string message)
{
if (id == llGetOwner())
{
else if (message == "Turn ON")
{
enabled  = TRUE;
llMessageLinked(LINK_THIS, 8439932,"enable", id);
}
else if (message == "Turn OFF")
{
enabled  = FALSE;
llMessageLinked(LINK_THIS, 8439932,"disable", id);
}
else if (message == "Echo ON")
{
isShowTran = TRUE;
llMessageLinked(LINK_THIS, 8872932,"echon", id);
}
else if (message == "Echo OFF")
{
isShowTran = FALSE;
llMessageLinked(LINK_THIS, 8872932,"echoff", id);
}
else if (message == "Objects OFF")
{
tranObjects = FALSE;
llMessageLinked(LINK_THIS, 8439742,"objoff", id);
}
else if (message == "Objects ON")
{
tranObjects = TRUE;
llMessageLinked(LINK_THIS, 8439742,"objon", id);
}
else if (message == "RESET")
{
llResetOtherScript("agents");
llResetOtherScript("form");
llResetOtherScript("trans");
llResetOtherScript("list");
llResetOtherScript("lan");
llOwnerSay("All Scripts are Resetted now...");
llResetScript();
}
}
}
//
//
sendIM(key imid, string imstr)
default
{
{
    if (llGetParcelFlags(llGetPos()) & PARCEL_FLAG_ALLOW_SCRIPTS)
state_entry()
{
llOwnerSay("Welcome to the Perrysonal Translator, probably the worst FREE translator in SL!");
randomDialogChannel = (integer)llFrand(2147483647);
llMessageLinked(LINK_SET, 7563297, "XTRNSL", NULL_KEY);
//Other Setup
llListen(randomDialogChannel, "", NULL_KEY, "");
showMainMenu(llGetOwner());
}
on_rez(integer start_param)
     {
     {
         llMessageLinked(LINK_ALL_CHILDREN, 85234119, imstr, imid);
         // Reset script when the object is rezzed
    }
         llResetScript();
    else
    {
         llMessageLinked(LINK_THIS, 85304563, imstr, imid);
     }
     }
touch_start(integer total_number)
{
if(llDetectedKey(0) == llGetOwner())
{
showMainMenu(llGetOwner());
}
}
listen(integer channel, string name, key id, string message)
{
processListen(name,id,message);
}
}
}
//txTxtLot() = sendTextBatch()
 
txTxtLot(integer txch, string txtxt)
 
</lsl>
 
Listener
<lsl>
// www.lsleditor.org  by Alphons van der Heijden (SL: Alphons Jano)
//(Mod made in Perry Mizin) I want to succeed with this translator... ;) call me day or night
//Universal Translator
//LSL Script copyright 2006-2009 by Hank Ramos
//Translation Web Services powered by Google
//listener
integer tranObjects = TRUE;
integer enabled = TRUE;
key restricted;
key owner;
//
default
{
{
    txtxt = llXorBase64StringsCorrect(llStringToBase64(txtxt), llStringToBase64(password));
state_entry()
     while (llStringLength(txtxt) > 508) //If string is 509 characters or longer
{
owner = llGetOwner();
llListen(0,"",NULL_KEY,"");
}
     on_rez(integer start_param)
     {
     {
         llSay(txch, llGetSubString(txtxt, 0, 507)); //send 508 character chunk
         // Reset script when the object is rezzed
         txtxt = llGetSubString(txtxt, 508, -1); //delete 508 character chunk
         llResetScript();
     }
     }
    llSay(txch, txtxt); //send out any remainder chunk or original chunk
link_message(integer sender_num, integer num, string str, key id)
    //Perry Mizin Comment: I don´t understand the aim of the following if.   
{
    //Hank Ramos Comment: this line serves to "trigger" the receiver not to wait for another batch.  If the
if (num == 8439932)
    //message length is exactly 508 characters, the receiver things that another chunk of the message is coming.
{
    //This message serves to tell the receiver that the last chunk was the last chunk, not another regular chunk.
if(str=="enable")
    if (llStringLength(txtxt) == 508)
{
        llSay(txch, (string)(txch*4958654));
enabled = TRUE;
    //Hank Ramos Comment: this just flashes the color of the bottom prim to show a message was sent
}
    llMessageLinked(LINK_ALL_CHILDREN, 6634934, (string)<0.25, 0, 0.25>, "");  
else if(str=="disable")
}
{
//string rxTxtLot() = string receiveTextBatch()
enabled = FALSE;
string rxTxtLot(key rxid, string rxmsg)
}
}
if (num == 8439742)
{
if(str=="objon")
{
tranObjects = TRUE;
}
else if(str=="objoff")
{
tranObjects = FALSE;
}
}
}
listen(integer channel, string name, key id, string message)
{
if(channel==PUBLIC_CHANNEL)
{
if (!enabled)
{
return;
}
if (restricted==id)
{
llSetTimerEvent(0.0);
restricted = id;
llSetTimerEvent(0.7);
return;
}
if (!tranObjects)
{
if (llGetAgentSize(id) == ZERO_VECTOR)
{
return;
}
}
if (llStringLength(message) < 12)
{
llMessageLinked(LINK_THIS,98745920,message,id);
}
else
{
llMessageLinked(LINK_THIS,7686795,message,id);
llMessageLinked(LINK_THIS,98745920,message,id);
}
llSetTimerEvent(0.7);
restricted = id;
}
}
timer()
{
restricted = NULL_KEY;
llSetTimerEvent(0.0);
}
}
 
</lsl>
 
 
agentsinTranslation
<lsl>
//(Mod made in Perry Mizin)
//Universal Translator
//Version 1.9.0
//December 25, 2009
//LSL Script copyright 2006-2009 by Hank Ramos
//Translation Web Services powered by Google
key owner;
key speaker;
key sid;
list agentsInTranslation;
list tmrli;
list newList;
integer listenID;
integer tmpavliPos;
integer ownerliPos;
vector tmrVct;
string actlan;
string tmplan;
string spkLan;
string SEPARATOR = "|%&|";
string mylanguage;
string checkLanguage(string chklantmpStr)
{
{
    integer rxliPos;
if (chklantmpStr == "")
    string  rxtmpStr = "";
{
    while (~llListFindList(sayCache, (list)rxid))
chklantmpStr = "en";
    {
}
        rxliPos = llListFindList(sayCache, [rxid]);
else if (chklantmpStr == "und")
        rxtmpStr = (rxtmpStr="") + rxtmpStr + llList2String(sayCache, rxliPos + 1);
{
        sayCache = llDeleteSubList(sayCache, rxliPos, rxliPos + 1);
chklantmpStr = "el";
    }
}
    rxmsg = rxtmpStr + rxmsg;
else if (chklantmpStr == "Gh")
    rxmsg = llBase64ToString(llXorBase64StringsCorrect(rxmsg, llStringToBase64(password)));
{
    return rxmsg;
chklantmpStr = "en";
}
if (llGetSubString(chklantmpStr, 0, 1) == "zh")
{
chklantmpStr = "zh-CN";
}
else
{
chklantmpStr = llGetSubString(chklantmpStr, 0, 1);
}
return chklantmpStr;
}
}
//string rxTxtLot() = string receiveTextBatch() (Another way)
string addNewAgent(key newavid)
integer rxTxtLotBusy = FALSE; //Perry Mizin: added Busy Mode, this could fail or prevent fail
string rxTxtLot(key rxid, string rxmsg)
{
{
    if (rxTxtLotBusy == FALSE)
string speakerLan;
    {
if (llGetAgentSize(newavid) == ZERO_VECTOR)
        rxTxtLotBusy = TRUE;
{
        integer rxliPos;
speakerLan = "en";
        string rxtmpStr = "";
}
        if(~llListFindList(sayCache, (list)rxid))
else
        {
{
            @rxin;
speakerLan = checkLanguage(llGetAgentLanguage(newavid));
            rxliPos = llListFindList(sayCache, [rxid]);
if (speakerLan == "")
            rxtmpStr = (rxtmpStr="") + rxtmpStr + llList2String(sayCache, rxliPos + 1);
{
            sayCache = llDeleteSubList(sayCache, rxliPos, rxliPos + 1);
speakerLan = "en";
            if(~llListFindList(sayCache, (list)rxid))
addAgent(newavid, speakerLan, 0);
            {
}
                jump rxin;
else
            }
{
        }
addAgent(newavid, speakerLan, 0);
        rxmsg = rxtmpStr + rxmsg;
}
        rxmsg = llBase64ToString(llXorBase64StringsCorrect(rxmsg, llStringToBase64(password)));
}
        rxTxtLotBusy = FALSE;
return speakerLan;
        return rxmsg;
    }
    else
    {
        //Perry Mizin: llSaySomething?
        return "";      
    }
}
}
//string rxTxtLotPrv() = string receiveTextBatchPrivate()
key getAgentKey(integer agentID)
string rxTxtLotPrv(key prxid, string prxmsg)
{
{
    integer prxliPos;
if(~llListFindList(agentsInTranslation, (list)agentID))
    string prxtmpStr = "";
{
    while (~llListFindList(sayCachePrivate, (list)prxid))
integer gkliPos = llListFindList(agentsInTranslation, (list)agentID);
    {
return llList2Key(agentsInTranslation, gkliPos - 4);
        prxliPos = llListFindList(sayCachePrivate, [prxid]);
}
        prxtmpStr = (prxtmpStr="") + prxtmpStr + llList2String(sayCachePrivate, prxliPos + 1);
else
        sayCachePrivate = llDeleteSubList(sayCachePrivate, prxliPos, prxliPos + 1);
{
    }
return NULL_KEY;
    prxmsg = prxtmpStr + prxmsg;
}
    prxmsg = llBase64ToString(llXorBase64StringsCorrect(prxmsg, llStringToBase64(password)));
}
    return prxmsg;
string List2TypeSep(list input2) {
integer w;
list output2;
for (w = 0; w < llGetListLength(input2); w++) {
output2 += [llGetListEntryType(input2, w)] + llList2List(input2, w, w);
}
return llDumpList2String(output2, SEPARATOR);
}
list TypeSep2List(string inputstring) {
integer v;
list input;
list output;
input = llParseString2List(inputstring, [SEPARATOR], []);
for (v = 0; v < llGetListLength(input); v += 2) {
if (llList2Integer(input, v) == TYPE_INTEGER) output += (integer)llList2String(input, v + 1);
else if (llList2Integer(input, v) == TYPE_FLOAT) output += (float)llList2String(input, v + 1);
else if (llList2Integer(input, v) == TYPE_STRING) output += llList2String(input, v + 1);
else if (llList2Integer(input, v) == TYPE_KEY) output += (key)llList2String(input, v + 1);
}
return output;
}
}
//updateTranslatorList()
addAgent(key avid, string avlan, integer chklan)
updateTranslatorList()
{
{
    integer nx;
integer avliPos;
    integer xliLng;
integer idNum;
    list    newList;
if (~llListFindList(agentsInTranslation, (list)avid))
    string  tmpStrPos;
{
    integer newMaster;
avliPos = llListFindList(agentsInTranslation, (list)avid);
    //Scan and remove translators not in the area
agentsInTranslation = llListReplaceList(agentsInTranslation, [avlan, avlan, chklan], avliPos + 1, avliPos + 3);
    xliLng = llGetListLength(translators);
}
    for (nx = 0; nx < xliLng; nx += 2)
else
    {
{
        tmpStrPos = llList2String(llGetObjectDetails(llList2Key(translators, nx + 1), [OBJECT_POS]), 0);
@at;
        if ((llVecDist(llGetPos(), (vector)tmpStrPos) <= 20.0) && (tmpStrPos != ""))
idNum = llRound(llFrand(2000000)) + 1;
        {
if(~llListFindList(agentsInTranslation, (list)idNum))
            newList = (newList=[]) + newList +  llList2List(translators, nx, nx + 1);
{
        }
jump at;
    }
}
    translators = newList;
agentsInTranslation = (agentsInTranslation=[]) + agentsInTranslation + [avid, avlan, avlan, chklan, idNum];
    //llMessageLinked(LINK_THIS,65635544,(string)xliLng,""); Perry Mizin: what is this necesary for?
}
    if (translators == [])
    {
        newMaster = 1;
    }
    else
    {
        if (enabled)
        {
            xliLng = llGetListLength(translators);
            newMaster = 2;
            for (nx = 0; nx < xliLng; nx += 2)
            {
                //llOwnerSay("Checking Priority Number(" +  (string)priorityNumber + "): " + (string)llList2Integer(translators, x));
                if (llList2Integer(translators, nx) > priorityNumber)
                {
                    newMaster = 0;
                }
            }
        }
        else
        {
            newMaster = 0;
        }
    }
    if ((isMaster > 0) && (newMaster == 0))
    {
        //We are being demoted from master to slave
        //Flush agentsInTranslation to master
        if (agentsInTranslation != [])
        {
            //Demotion Dump of agentsInTranslation to Master
            txTxtLot(broadcastChannel, llList2CSV([1003, llList2CSV(agentsInTranslation)]));
            if (isInitialized == FALSE)
            {
                return;
            }
            txTxtLot(broadcastChannel, llList2CSV([1004, options])); //error
        }
        llListenRemove(listenID);
    }
    if ((isMaster == 0) && (newMaster > 0))
    {
        llListenRemove(listenID);
        listenID = llListen(0, "", "", "");
    }
    isMaster = newMaster;
    llMessageLinked(LINK_THIS, 34829304, (string)isMaster, "");
}
}
//sendHeartbeat()
//
sendHeartbeat()
default
{
{
    updateTranslatorList();
state_entry()
    txTxtLot(broadcastChannel, llList2CSV([1001, priorityNumber]));
{
    //Broadcast agentList to Slaves
owner = llGetOwner();
    if (isMaster == 2)
listenID = llListen(0, "", "", "");
    {
mylanguage = llGetAgentLanguage(owner);
        txTxtLot(broadcastChannel, llList2CSV([1002, llList2CSV(agentsInTranslation)]));
if (llStringLength(mylanguage) < 1)
    }
{
mylanguage = "en";
}
if(~llListFindList(agentsInTranslation, (list)owner))
{
ownerliPos = llListFindList(agentsInTranslation, (list)owner);
agentsInTranslation = llListReplaceList(agentsInTranslation, [mylanguage] , ownerliPos + 1, ownerliPos + 1);
}
else
{
agentsInTranslation = (agentsInTranslation=[]) + agentsInTranslation + [owner, mylanguage, mylanguage, 0, llRound(llFrand(2000000)) + 1];
}
llSetTimerEvent(1.0);
}
link_message(integer sender_num, integer num, string lstr, key lid)
{
if (num == 6349160)
{
speaker = lid;
spkLan = lstr;
if (~llListFindList(agentsInTranslation, (list)speaker))
{
tmpavliPos = llListFindList(agentsInTranslation, (list)speaker);
actlan = llList2String(agentsInTranslation, tmpavliPos + 1);
tmplan = llList2String(agentsInTranslation, tmpavliPos + 2);
if (llList2Integer(agentsInTranslation, tmpavliPos + 3) >= 2)
// if anyone speaks on any different language 3 times in a row
addAgent(lid, lstr, 0);
}
if (actlan == lstr)
{  // reset language checker for speaker
agentsInTranslation = llListReplaceList(agentsInTranslation, [actlan, 0], tmpavliPos + 2, tmpavliPos + 3);
}
else
{
if (lstr == tmplan)
{   // if language of speaker is not the same as detected language
agentsInTranslation = llListReplaceList(agentsInTranslation,[llList2Integer(agentsInTranslation,tmpavliPos + 3) + 1] , tmpavliPos + 3, tmpavliPos + 3);
}
else
{
agentsInTranslation = llListReplaceList(agentsInTranslation,[lstr, 0] , tmpavliPos + 2, tmpavliPos + 3);
}
}
}
}
if (num == 9876754)
{
llMessageLinked(LINK_THIS,7659759,List2TypeSep(agentsInTranslation),NULL_KEY);
}
}
listen(integer channel, string name, key id, string message)
{
if(~llListFindList(agentsInTranslation, (list)id))
{ }
else
{
addNewAgent(id);
}
}
sensor(integer num_detected)
{
integer s;
for (s = 0; s < num_detected; s += 1)
{
sid = llDetectedKey(s);
if (~llListFindList(agentsInTranslation, (list)sid))
{ }
else
{
addNewAgent(sid);
}
}
}
no_sensor()
{ }
timer()
{
llSetTimerEvent(0.0);
integer r;
for (r = 0; r < llGetListLength(agentsInTranslation); r += 5)
{
tmrli = llGetObjectDetails(llList2Key(agentsInTranslation, r), [OBJECT_POS]);
tmrVct = llList2Vector(tmrli, 0);
if (tmrVct == ZERO_VECTOR)
{  }
else
{
if (llVecDist(llGetPos(), tmrVct) <= 20.0)
{
newList = (newList=[]) + newList + llList2List(agentsInTranslation, r, r + 4);
}
}
}
agentsInTranslation = newList;
newList = [];
llSensor("",NULL_KEY,AGENT,20.0,PI);
llSetTimerEvent(6.0);   // restart timer
}
}
}
//checkThrottle()
</lsl>
checkThrottle(integer chkn, string chkmsg, list chkli)
 
 
DetectLanguage
<lsl>
//(Mod made in Perry Mizin)
//Universal Translator
//Version 1.9.0
//December 25, 2009
//LSL Script copyright 2006-2009 by Hank Ramos
//Translation Web Services powered by Google
key dtcValue;
key speakerID;
string htttmpStr;
list tempDetections;
list newList;
float timeElapsed;
integer tmpliPos;
integer contains(string haystack, string needle) // http://wiki.secondlife.com/wiki/llSubStringIndex
{
{
    integer y;
return ~llSubStringIndex(haystack, needle);
    integer maxCount;
    float  chkoldTime;
    float  sleepTime;
    list    chknewli;
    key    returnValue;
    integer channelToSpeak;
    //loop though list and remove items older than 25 seconds
    for (y = 0; y < llGetListLength(requestList); y += 1)
    {
        chkoldTime = llList2Float(requestList, y);
        //Construct new list with only times less than 25 seconds
        if ((llGetTime() - chkoldTime) <= 25.0)
        {
            chknewli = (chknewli=[]) + chknewli + [chkoldTime];
        }
    }
    requestList = chknewli;
    y = llGetListLength(requestList);
    //Shunt all translations to linked translators if master
    if (isMaster == 2)
    {
        if (chkn == 0)
        {
            //Send HTTP request to other translator
            //Send out Request to Random Translator Channel
            channelToSpeak = llList2Integer(llListRandomize(llList2ListStrided(translators, 0, -1, 2), 1), 0);
            if (channelToSpeak > 0)
            {
                txTxtLot(channelToSpeak, llList2CSV([chkn, llList2CSV(chkli)]) + "~" + chkmsg);
                return;
            }
        }
    }
    if (y == 19)
    {
        sleepTime =  25.0 - (llGetTime() - llList2Float(requestList, 0));
        if (sleepTime > 0)
        {
            llSleep(sleepTime);
        }
        requestList = llDeleteSubList(requestList, 0, 0);
    }
    if (chkn == 0)
    {
        chkmsg = "translate?v=1.0&q=" + chkmsg;
    }
    else
    {
        chkmsg = "detect?v=1.0&q=" + chkmsg;
    }
    requestList = (requestList=[]) + requestList + (list)llGetTime();
    returnValue = llHTTPRequest("http://ajax.googleapis.com/ajax/services/language/" + chkmsg, [HTTP_METHOD, "GET", HTTP_MIMETYPE, "plain/text;charset=utf-8"], " ");
    if (returnValue != NULL_KEY)
    {
        if (chkn == 0)
        {
            llMessageLinked(LINK_THIS, 235365342, llList2CSV(chkli), returnValue);  
        }
        else
        {
            llMessageLinked(LINK_THIS, 235365343, llList2CSV(chkli), returnValue);
        }
    }
    else
    {
        llSleep(40.0); //Something has gone horribly wrong, sleep 40 seconds to clear throttle
    }
}
}
//string checkLanguage()
DetectLanguage(string dtcmsg, key dtcid)
string checkLanguage(string chklantmpStr)
{
{
    if (llGetSubString(chklantmpStr, 0, 1) == "zh")
dtcValue = llHTTPRequest("http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=" + llEscapeURL(dtcmsg), [HTTP_METHOD, "GET", HTTP_MIMETYPE, "plain/text;charset=utf-8"], " ");
    {
if (dtcValue != NULL_KEY)
        chklantmpStr = "zh-CN";
{
    }
tempDetections = (tempDetections=[]) + tempDetections + [dtcValue, dtcid, llGetTime()];
    else if (chklantmpStr == "und")
}
    {
else
        chklantmpStr = "el";
{
    }
llSleep(10.0); // Something has gone horribly wrong, sleep 10 seconds clear throttle
    if (~llListFindList(languageCodes, [chklantmpStr]))
}
    {
    } else {
        chklantmpStr = "";
    }
    chklantmpStr = llGetSubString(chklantmpStr, 0, 1);
    return chklantmpStr;
}
}
//addAgent()
//
addAgent(key avid, string avlan, integer chklan)
default
{
{
    integer avliPos;
state_entry()
    integer idNum;
{
    if (~llListFindList(agentsInTranslation, (list)avid))
llSetTimerEvent(5.0);
    {
}
        avliPos = llListFindList(agentsInTranslation, [avid]);
link_message(integer sender, integer num, string msg, key id)
        agentsInTranslation = llListReplaceList(agentsInTranslation, [avlan, chklan], avliPos + 1, avliPos + 2);
{
    }
if (num == 7686795)
    else
{
    {
DetectLanguage(msg, id);
        @at;
}
        idNum = llRound(llFrand(2000000)) + 1;
}
        if(~llListFindList(agentsInTranslation, (list)idNum))
http_response(key request_id, integer status, list metadata, string body)
        {//it exists     
{  // Process Response Code
            jump at;
if (~llListFindList(tempDetections, (list)request_id))
        }
{   // Language Detection
        agentsInTranslation = (agentsInTranslation=[]) + agentsInTranslation + [avid, avlan, chklan, idNum];
tmpliPos = llListFindList(tempDetections, (list)request_id);
        llMessageLinked(LINK_THIS, 64562349, avlan, avid);      
speakerID = llList2Key(tempDetections, tmpliPos + 1);
    }
tempDetections = llDeleteSubList(tempDetections, tmpliPos, tmpliPos + 2);
htttmpStr = llToLower(llGetSubString(body, llSubStringIndex(body, "{\"language\":\"") + 13, llSubStringIndex(body, "\",\"isReliable\":") - 1));
if (contains(htttmpStr, "err") == 0 && contains(htttmpStr, "unn") == 0)
{   // We Trust the Google system, the Google´s guys are good and I am sure they will keep improving :-)
if(llStringLength(htttmpStr) <= 3)
{
llMessageLinked(LINK_THIS,6349160,htttmpStr,speakerID);
}
}
}
}
timer()
{
llSetTimerEvent(0.0);
integer r;
integer TliLen = llGetListLength(tempDetections);
for (r = 0; r < TliLen; r += 3)
{
timeElapsed = llGetTime() - llList2Float(tempDetections, r + 2);
if (timeElapsed > 10.0)
{
newList = (newList=[]) + newList + llList2List(tempDetections, r, r + 2);
}
}
tempDetections = newList;
newList = [];
llSetTimerEvent(5.0);
}
}
}
//string addNewAgent()
 
string addNewAgent(key newavid)
</lsl>
 
 
Formulator
<lsl>
//(Mod made in Perry Mizin)
//Universal Translator
//Version 1.9.0
//December 25, 2009
//LSL Script copyright 2006-2009 by Hank Ramos
//Translation Web Services powered by Google
//Formulator Script
list agentsInTranslation;
list txli;
list translationCache;
list tomali;
string SEPARATOR = "|%&|";
string recepientLanguage;
string speakerLanguage;
string txmessage;
string  spkrLan;
string recep;
string  recepLan;
string  lanpair;
string request;
integer M = 1;
integer rxID;
integer recepID;
integer lstliPos;
integer lstliPos2;
integer txPos;
integer lint;
key recepientID;
float cacheTime;
sendIM(key imid, string imstr)
{
{
    string speakerLan;
if (M == 8)
{
    if (llGetAgentSize(newavid) != ZERO_VECTOR)
llMessageLinked(LINK_ALL_OTHERS,2334420,imstr,imid);
    {
M = 1;
        speakerLan  = checkLanguage(llGetAgentLanguage(newavid));
}
        if (speakerLan == "")
else if (M == 7)
        {
{
            speakerLan = "en";
llMessageLinked(LINK_ALL_OTHERS,2334430,imstr,imid);
            addAgent(newavid, speakerLan, TRUE);
M = 8;
        }
}
        else
else if (M == 6)
        {
{
            addAgent(newavid, speakerLan, FALSE);
llMessageLinked(LINK_ALL_OTHERS,2334440,imstr,imid);
        }
M = 7;
    }
}
    return speakerLan;
else if (M == 5)
{
llMessageLinked(LINK_ALL_OTHERS,2334450,imstr,imid);
M = 6;
}
else if (M == 4)
{
llMessageLinked(LINK_ALL_OTHERS,2334460,imstr,imid);
M = 5;
}
else if (M == 3)
{
llMessageLinked(LINK_ALL_OTHERS,2334470,imstr,imid);
M = 4;
}
else if (M == 2)
{
llMessageLinked(LINK_ALL_OTHERS,2334480,imstr,imid);
M = 3;
}
else if (M == 1)
{
llMessageLinked(LINK_ALL_OTHERS,2334490,imstr,imid);
M = 2;
}
}
}
//key getAgentKey()
key getAgentKey(integer agentID)
key getAgentKey(integer agentID)
{
{
    if(~llListFindList(agentsInTranslation, (list)agentID))
if(~llListFindList(agentsInTranslation, (list)agentID))
    {
{
        integer gkliPos = llListFindList(agentsInTranslation, [agentID]);
integer gkliPos = llListFindList(agentsInTranslation, (list)agentID);
        return llList2Key(agentsInTranslation, gkliPos - 3);
return llList2Key(agentsInTranslation, gkliPos - 4);
    }
}
    else
else
    {
{
        return "";
return NULL_KEY;
    }
}
}
list TypeSep2List(string inputstring)
{
integer h;
list input;
list output;
input = llParseString2List(inputstring, [SEPARATOR], []);
for (h = 0; h < llGetListLength(input); h += 2)
{
if (llList2Integer(input, h) == TYPE_INTEGER) output += (integer)llList2String(input, h + 1);
else if (llList2Integer(input, h) == TYPE_FLOAT) output += (float)llList2String(input, h + 1);
else if (llList2Integer(input, h) == TYPE_STRING) output += llList2String(input, h + 1);
else if (llList2Integer(input, h) == TYPE_KEY) output += (key)llList2String(input, h + 1);
}
return output;
}
string List2TypeSep(list input2)
{
integer l;
list output2;
for (l = 0; l < llGetListLength(input2); l++)
{
output2 += [llGetListEntryType(input2, l)] + llList2List(input2, l, l);
}
return llDumpList2String(output2, SEPARATOR);
}
//
default
{
state_entry()
{
llSetTimerEvent(1.0);
}
link_message(integer sender_num, integer num, string lstr, key id)
{
if (num == 7659759)
{
agentsInTranslation = TypeSep2List(lstr);
}
if (num == 9827491)
{
txli = TypeSep2List(lstr);
rxID = llList2Integer(txli,0);
speakerLanguage = llList2String(txli,1);
txmessage = llList2String(txli,2);
lint = llListFindList(agentsInTranslation, (list)rxID);
recepientLanguage = llList2String(agentsInTranslation, lint - 3);
recepientID = getAgentKey(rxID);
if (recepientID != NULL_KEY)
{
if (recepientLanguage == speakerLanguage)
{ }
else
{
sendIM(recepientID,txmessage);
}
}
}
if (num == 98745920)
{
txPos = llListFindList(agentsInTranslation, (list)id);
cacheTime = llGetTime();
if(id==llGetOwner())
{
integer v;
integer agentslilen = llGetListLength(agentsInTranslation);
for (v = 0; v < agentslilen; v += 5)
{
spkrLan = llList2String(agentsInTranslation, txPos + 1);
recepID = llList2Integer(agentsInTranslation, v + 4);
recepLan = llList2String(agentsInTranslation, v + 1);
if (spkrLan == recepLan)
{ }
else
{
lanpair = spkrLan + "|" + recepLan;
if (~llListFindList(translationCache, (list)lanpair))
{
lstliPos = llListFindList(translationCache, (list)lanpair);
translationCache = llListReplaceList(translationCache, [llList2String(translationCache, lstliPos + 1) + "@" + (string)recepID], lstliPos + 1, lstliPos + 1);
}
else
{
translationCache = (translationCache=[]) + translationCache + [lanpair, recepID, cacheTime];
}
}
}
if (translationCache != [])
{
integer w;
for (w = 0; w < llGetListLength(translationCache); w += 3)
{
lanpair = llList2String(translationCache, w);
recep = llList2String(translationCache, w + 1);
tomali = [lstr, lanpair, recep];
request = List2TypeSep(tomali);
llMessageLinked(LINK_THIS,2346017,request,id);
}
}
}
else
{
lstliPos2 = llListFindList(agentsInTranslation, (list)llGetOwner());
if (~llListFindList(agentsInTranslation, (list)id))
{
spkrLan = llList2String(agentsInTranslation, txPos + 1);
recepID = llList2Integer(agentsInTranslation, lstliPos2 + 4);
recepLan = llList2String(agentsInTranslation, lstliPos2 + 1);
if (spkrLan == recepLan)
{ }
else
{
lanpair = spkrLan + "|" + recepLan;
if (~llListFindList(translationCache, (list)lanpair))
{
lstliPos = llListFindList(translationCache, (list)lanpair);
translationCache = llListReplaceList(translationCache, [llList2String(translationCache, lstliPos + 1) + "@" + (string)recepID], lstliPos + 1, lstliPos + 1);
}
else
{
translationCache = (translationCache=[]) + translationCache + [ lanpair, recepID, cacheTime ];
}
}
}
if (translationCache != [])
{    // Process Requests
tomali = [lstr, lanpair, recepID];
request = List2TypeSep(tomali);
llMessageLinked(LINK_THIS,2346017,request,id);
}
}
}
}
timer()
{
llSetTimerEvent(0.0);
float timeElapsed;
list newList;
integer r;
for (r = 0; r < llGetListLength(translationCache); r += 3)
{
timeElapsed = llGetTime() - llList2Float(translationCache, r + 2);
if (timeElapsed < 10.0)
{
newList = (newList=[]) + newList + llList2List(translationCache, r, r + 2);
}
}
translationCache = newList;
newList = [];
llMessageLinked(LINK_THIS,9876754,"",NULL_KEY);
llSetTimerEvent(12.0);
}
}
</lsl>
 
Translator
<lsl>
//(Mod made in Perry Mizin)
//Universal Translator
//Version 1.9.0
//December 25, 2009
//LSL Script copyright 2006-2009 by Hank Ramos
//Translation Web Services powered by Google
list paramtmpli;
list recepientList;
list requestedTranslations;
list forli;
list txli;
list txli2;
list lkli;
string SEPARATOR = "|%&|";
string recepientLanguage;
string languagePair;
string speakerName;
string speakerLanguage;
string translatedText;
string lantmpStr;
string lmsg;
string llan;
string sendim;
string request;
string llid;
key speakerID;
key returnValue;
key tid;
integer tranObjects = TRUE;
integer isMaster = 1;
integer enabled = FALSE;
integer httliPos;
integer lmPos;
integer httbusy;
Translate(string chkmsg, list chkli)
{
returnValue = llHTTPRequest("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" + llEscapeURL(chkmsg) + "&langpair=" + llList2String(chkli,2), [HTTP_METHOD, "GET", HTTP_MIMETYPE, "plain/text;charset=utf-8"], "");
if (returnValue != NULL_KEY)
{
requestedTranslations = (requestedTranslations=[]) + requestedTranslations + [returnValue];
requestedTranslations = (requestedTranslations=[]) + requestedTranslations + chkli;
}
else
{
llOwnerSay("ERROR ERROR ERROR ERROR ERRORR ERROOOORRRRR");
llOwnerSay("All Go!");
llSleep(25.0);
}
}
string List2TypeSep(list input) {
integer v;
list output;
for (v = 0; v < llGetListLength(input); v++) {
output += [llGetListEntryType(input, v)] + llList2List(input, v, v);
}
return llDumpList2String(output, SEPARATOR);
}
list TypeSep2List(string inputstring)
{
integer w;
list input2;
list output2;
input2 = llParseString2List(inputstring, [SEPARATOR], []);
for (w = 0; w < llGetListLength(input2); w += 2) {
if (llList2Integer(input2, w) == TYPE_INTEGER) output2 += (integer)llList2String(input2, w + 1);
else if (llList2Integer(input2, w) == TYPE_FLOAT) output2 += (float)llList2String(input2, w + 1);
else if (llList2Integer(input2, w) == TYPE_STRING) output2 += llList2String(input2, w + 1);
else if (llList2Integer(input2, w) == TYPE_KEY) output2 += (key)llList2String(input2, w + 1);
}
return output2;
}
//
default
{
state_entry()
{
httbusy=FALSE;
llSetTimerEvent(1.0);
}
link_message(integer sender_num, integer num, string lstr, key lid)
{
if (num == 2346017)
{
if(httbusy==FALSE)
{
httbusy = TRUE;
if (~llListFindList(txli2, (list)lstr))
{
lmPos = llListFindList(txli2, (list)lstr);
txli2 = llDeleteSubList(txli2, lmPos, lmPos + 1);
txli = TypeSep2List(lstr);
lmsg = llList2String(txli,0);
llan = llList2String(txli,1);
llid = llList2String(txli,2);
lkli = [ llGetTime(), lid, llan, llid ];
Translate(lmsg,lkli);
}
else
{
txli = TypeSep2List(lstr);
lmsg = llList2String(txli,0);
llan = llList2String(txli,1);
llid = llList2String(txli,2);
lkli = [ llGetTime(), lid, llan, llid ];
Translate(lmsg,lkli);
}
}
else
{
if (~llListFindList(txli2, (list)lstr))
{ }
else
{
txli2 = (txli2=[]) + txli2 + [lstr];
txli2 = (txli2=[]) + txli2 + [lid];
}
}
}
}
http_response(key request_id, integer status, list metadata, string body)
{  // Process Response Code
if (~llListFindList(requestedTranslations, (list)request_id))
{  // Translation
httliPos = llListFindList(requestedTranslations, (list)request_id);
speakerID  = llList2Key(requestedTranslations, httliPos + 2);
speakerName = llKey2Name(speakerID);
if (llStringLength(speakerName) < 3)
{
speakerName = llList2String(llGetObjectDetails(speakerID, [OBJECT_NAME]), 0);
}
recepientList = llParseString2List(llList2String(requestedTranslations, httliPos + 4),["@"],[]);
paramtmpli = llParseStringKeepNulls(llList2String(requestedTranslations, httliPos + 3),["|"],[]);
speakerLanguage = llList2String(paramtmpli, 0);
recepientLanguage = llList2String(paramtmpli, 1);
languagePair = llDumpList2String(paramtmpli, ">>");
// Perform Text Cleanup
translatedText = llGetSubString(body, llSubStringIndex(body, "{\"translatedText\":\"") + 18, llSubStringIndex(body, "}, \"responseDetails\"") -1);
// Reverse order if Recepient Language is Hebrew or Arabic
if ((recepientLanguage == "iw") || (recepientLanguage == "ar"))
{
lantmpStr = "";
integer q;
for(q = llStringLength(translatedText);q >= 0; q--)
{
lantmpStr = (lantmpStr="") + lantmpStr + llGetSubString(translatedText, q, q);
}
translatedText = lantmpStr;
}
lantmpStr = speakerName + "(" + languagePair + "): " + translatedText;
integer z;
integer reclen = llGetListLength(recepientList);
for (z = 0; z < reclen; z += 1)
{
forli = [llList2Integer(recepientList, z), speakerLanguage , lantmpStr];
sendim = List2TypeSep(forli);
llMessageLinked(LINK_THIS,9827491,sendim,NULL_KEY);
}
requestedTranslations = llDeleteSubList(requestedTranslations, httliPos, httliPos + 4);
httbusy = FALSE;
llSetTimerEvent(1.0);
}
}
timer()
{
llSetTimerEvent(0.0);
if(txli2 != [])
{
integer m;
integer lleng = llGetListLength(txli2);
for (m = 0; m < lleng; m += 2)
{
request = llList2String(txli2, m);
tid = llList2Key(txli2, m + 1);
llMessageLinked(LINK_THIS,2346017,request,tid);
}
}
float timeElapsed;
list newList;
integer r;
for (r = 0; r < llGetListLength(requestedTranslations); r += 6)
{
timeElapsed = llGetTime() - llList2Float(requestedTranslations, r + 1);
if (timeElapsed < 20.0)
{
newList = (newList=[]) + newList + llList2List(requestedTranslations, r, r + 5);
}
}
requestedTranslations = newList;
newList = [];
llSetTimerEvent(5.0);
}
}
}
//processHTTPResponse()
</lsl>
processHTTPResponse(integer ntype, string bodyStr, list paramsli)
 
IM handler
<lsl>
// www.lsleditor.org  by Alphons van der Heijden (SL: Alphons Jano)
//(Mod made in Perry Mizin) I want to succeed with this translator... ;) call me day or night
//Universal Translator
//Version 1.9.0
//December 25, 2009
//LSL Script copyright 2006-2009 by Hank Ramos
//Translation Web Services powered by Google
integer echo;
list escape=["\\u0026#39;" , "'" , "\\u003d" , "=" , "\\u0026amp;" , "&" , "\\u0026lt;" , "<" , "\\u0026gt;" , ">" , "\\u0026quot;" , "\""];
string Escape(string text)
{
{
     integer spkliPos;
     integer i; string result;
    list    recepientList;
     list t=llParseString2List(text,[],["\\u0026#39;","\\u003d","\\u0026amp;","\\u0026lt;","\\u0026gt;","\\u0026quot;"]);
    key    recepientID;
     for(i=0;i<llGetListLength(t);i++)
    string recepientLanguage;
     string  languagePair;
    key    speakerID;
    string  speakerName;
    string  speakerLanguage;
    string  translatedText;
    string  lantmpStr;
    integer z;
    integer speakerLanguageReliable;
    float  speakerLanguageConfidence;
     list    paramtmpli;
    //===================
    //Process Translation
    //===================
    if (ntype == 0)
     {
     {
         speakerID  = llList2Key(paramsli, 1);
         integer ii=llListFindList(escape,[llList2String(t,i)]);
        speakerName = llKey2Name(speakerID);
         if(ii!=-1)
        if (speakerName == "")
        {
            speakerName = llList2String(llGetObjectDetails(speakerID, [OBJECT_NAME]), 0);
        }
        recepientList = llParseString2List(llList2String(paramsli, 2), ["@"], []);
         paramtmpli = llParseStringKeepNulls(llList2String(paramsli, 3), ["|"],[]);
        recepientLanguage = llList2String(paramtmpli, 1);
        languagePair = llDumpList2String(paramtmpli, ">>");
        //Perform Text Cleanup
        z = llSubStringIndex(bodyStr, "\",\"detectedSourceLanguage\":\"");
        if (z != -1)
        {
            translatedText  = llGetSubString(bodyStr, llSubStringIndex(bodyStr, "{\"translatedText\":\"") + 18, z);
            speakerLanguage = checkLanguage(llGetSubString(bodyStr, z + 28, llSubStringIndex(bodyStr, "\"}, \"responseDetails\":") - 1));
            spkliPos = llListFindList(agentsInTranslation, [speakerID]);
            if (spkliPos >= 0)
            {
                if (speakerLanguage != llList2String(agentsInTranslation, spkliPos + 1))
                {
                    agentsInTranslation = llListReplaceList(agentsInTranslation, [TRUE], spkliPos + 2, spkliPos + 2);  //Mark for recheck of actual spoken language.
                }
            }                 
        }
        else if (z == -1)
        {
            translatedText = llGetSubString(bodyStr, llSubStringIndex(bodyStr, "{\"translatedText\":\"") + 18, llSubStringIndex(bodyStr, "\"}, \"responseDetails\""));
        }
        //Reverse order if Recepient Language is Hebrew or Arabic
        if ((recepientLanguage == "iw") || (recepientLanguage == "ar"))
         {
         {
             lantmpStr = "";
             t=llListReplaceList(t,[llList2String(escape,ii+1)],i,i);
            //Perry Mizin Comment: Probably I guess this is wrong, maybe I am wrong
            //Perry Mizin Comment: alternative reverse order: "Hello World" could be "World Hello"
            //Perry Mizin Comment: reverse order: "Hello World" is "dlroW olleH" or ,,pl^ºM ºllªH,,
            for(z = llStringLength(translatedText);z >= 0; z--)
            {
                lantmpStr = (lantmpStr="") + lantmpStr + llGetSubString(translatedText, z, z);
            }
            translatedText = lantmpStr;
        } 
        lantmpStr = speakerName + "(" + languagePair + "): " + translatedText;
        if (showTranslation)
        {
            sendIM(speakerID, lantmpStr);
        }
        for (z = 0; z < llGetListLength(recepientList); z += 1)
        {
            recepientID = getAgentKey(llList2Integer(recepientList, z));
            if (recepientID != "")
            {
                recepientLanguage = llList2String(agentsInTranslation, llListFindList(agentsInTranslation, [recepientID]) + 1);
                if (recepientLanguage != speakerLanguage)
                {
                    sendIM(recepientID, lantmpStr);
                }
            } 
         }
         }
        return;
     }
     }
     //===========================
     result=llDumpList2String(t,"");
     //Process Language Detection
     return result;
    //===========================
}
     if (ntype == 1)
 
sendim(string mess, key target)
{
     if (llGetAgentSize(target) == ZERO_VECTOR)
    { }
    else
     {
     {
         speakerID = llList2Key(paramsli, 1);
         llInstantMessage(target, llUnescapeURL(mess));
        speakerLanguageReliable = llToLower(llGetSubString(bodyStr, llSubStringIndex(bodyStr, "\",\"isReliable\":") + 15, llSubStringIndex(bodyStr, ",\"confidence\":") - 1)) == "true";
         if(echo==TRUE)
         speakerLanguageConfidence = (float)llGetSubString(bodyStr, llSubStringIndex(bodyStr, ",\"confidence\":") + 14, llSubStringIndex(bodyStr, "}, \"responseDetails\":") - 1);
        spkliPos = llListFindList(agentsInTranslation, [speakerID]);
        if (((spkliPos < 0) && (speakerLanguageReliable) || (speakerLanguageConfidence >= 0.08)))
         {
         {
             //Analyze Data
             llOwnerSay(mess + " @" + llKey2Name(target));
            lantmpStr = checkLanguage(llToLower(llGetSubString(bodyStr, llSubStringIndex(bodyStr, "{\"language\":\"") + 13, llSubStringIndex(bodyStr, "\",\"isReliable\":") - 1)));
            if (lantmpStr == "")
            {
                return;
            }
            if (speakerLanguageConfidence < 0.14)
            {
                addAgent(speakerID, lantmpStr, TRUE);
            }
            else
            {
                addAgent(speakerID, lantmpStr, FALSE);
            }
         }
         }
     }  
     }
}
}


default
default
Line 500: Line 1,084:
     state_entry()
     state_entry()
     {
     {
         //Multiplexor Initialization
         echo=FALSE;
        priorityNumber = version*1000000 + llRound(llFrand(499999) + 50000);
         llSleep(0.1);
         llListen(broadcastChannel, "", NULL_KEY, "");
        priorityNumListenID = llListen(priorityNumber, "", NULL_KEY, "");
        //Send out initial heartbeat
        lastHeartBeat = llGetUnixTime();
        txTxtLot(broadcastChannel, llList2CSV([1001, priorityNumber]));
        //Wait for the network to settle down
        llSetTimerEvent(5.0);
        //llSetTimerEvent(10 + ((1-llGetRegionTimeDilation()) * 1));      
     }
     }


     link_message(integer sender_num, integer num, string lstr, key lid)
     link_message(integer sender_num, integer num, string str, key id)
     {
     {
        list    ltmpli;
         if (num == 2334420)
 
        //Old Multiplexor
         if (num == 8434532)
         {
         {
             enabled = (integer)lstr;
             sendim(Escape(str),id);
         }
         }
        else if (num == 3342976)
        {
            //Send Preferences
            options = lstr;
            if (isInitialized == FALSE) return;
            ltmpli = llCSV2List(options);
            showTranslation = llList2Integer(ltmpli, 0);
            tranObjects = llList2Integer(ltmpli, 1);
            autoLanguage = llList2Integer(ltmpli, 2);
            txTxtLot(broadcastChannel, llList2CSV([1004, options]));
        }
        else if (num == 9384610)
        {
            if (isMaster == 0) //markering
                //llMessageLinked(LINK_THIS, 5598321, llList2CSV([id, str, FALSE]), "");
                txTxtLot(broadcastChannel, llList2CSV([1003, lid, lstr, FALSE]));
            else
                addAgent(lid, lstr, TRUE);
        }
        else if (num == 345149625)
        {
            //Return Translation
            processHTTPResponse(0, lstr, llCSV2List(lid));
        }
        else if (num == 345149626)
        {
            //Return Detection
            processHTTPResponse(1, lstr, llCSV2List(lid));
        }
    }
    sensor(integer num_detected)
    {
        integer s;
        key    sid;
        for (s = 0; s < num_detected; s += 1)
        {
            sid = llDetectedKey(s);
            if (~llListFindList(agentsInTranslation, (list)sid))
            {
               
            } else {
                addNewAgent(sid);
            }
        }
    }
          
          
    listen(integer channel, string name, key id, string message)
         if (num == 8872932)
    {
        integer w;
        string  spkrLan;
        string  recepLan;
        integer recepID;
        integer lstliPos;
        string  lanpair;
        list    translationCache;
        list    lsttmpli;
        integer ImessageType;
        string  Imessage;
        string  lsttmpStr;
        string  lst2tmpStr;
        //Multiplexor Code
         if ((channel == broadcastChannel) || (channel == priorityNumber))
         {
         {
            //==========================
             if(str=="echon")
            //Process Proxy HTTP Request
            //==========================
             if (channel == priorityNumber)
             {
             {
                 if (llStringLength(message) >= 508)
                 echo=TRUE;
                {
                    if (((integer)message/channel) != 4958654)
                    {
                        sayCachePrivate = (sayCachePrivate=[]) + sayCachePrivate + [id, message];
                        return;
                    }
                    message = "";
                }
                message = rxTxtLotPrv(id, message);
                //Received packet to translate
                llMessageLinked(LINK_ALL_CHILDREN, 6634934, (string)<0.25, 0.05, 0.25>, "");
                lsttmpli = llParseString2List(message, ["~"], []);
                lsttmpStr = llList2String(lsttmpli, 0);
                lsttmpli = llDeleteSubList(lsttmpli, 0, 0);
                lst2tmpStr = llDumpList2String(lsttmpli, "|");
                lsttmpli = llCSV2List(lsttmpStr);
                lstliPos = llList2Integer(lsttmpli, 0);
                lsttmpli = llDeleteSubList(lsttmpli, 0, 0);
                checkThrottle(lstliPos, lst2tmpStr, lsttmpli);
                return;
             }
             }
             if(str=="echoff")
            //=======================
            //Process Global Messages
            //=======================
             if (llStringLength(message) >= 508)
             {
             {
                 if (((integer)message/channel) != 4958654)
                 echo=FALSE;
                {
                    sayCache = (sayCache=[]) + sayCache + [id, message];
                    return;
                }
                message = "";
             }
             }
            message = rxTxtLot(id, message);
            lsttmpli = llCSV2List(message);
            if (llGetListLength(lsttmpli) >= 2)   
            {
                ImessageType = llList2Integer(lsttmpli, 0);
                lsttmpli = llDeleteSubList(lsttmpli, 0, 0);
                Imessage = llList2CSV(lsttmpli);       
                llMessageLinked(LINK_ALL_CHILDREN, 6634934, (string)<0.25, 0, 0.25>, "");
                //Process Message Here
                if (ImessageType == 1001)
                {
                    //Incoming Heartbeat
                    if ((integer)Imessage == priorityNumber)
                    {
                        llOwnerSay("Priority Number Conflict!  Resetting Script...");
                        llResetScript(); //Reset if conflicting priority number
                    }
                    lstliPos = llListFindList(translators, [id]);
                    if (lstliPos < 0)
                    {
                        translators = (translators=[]) + translators + [(integer)Imessage, id];
                        if ((isMaster > 0) && (isInitialized))
                        {
                            txTxtLot((integer)Imessage, llList2CSV([1002, llList2CSV(agentsInTranslation)]));
                            txTxtLot((integer)Imessage, llList2CSV([1004, options]));
                        }
                    }
                    else
                    {
                        translators = llListReplaceList(translators, [(integer)Imessage], lstliPos - 1, lstliPos - 1);
                    }
                }
                else if (ImessageType == 1002)
                {
                    //Incoming agentsInTranslation Master Broadcast
                    if (isMaster == 0)
                    {
                        //llMessageLinked(LINK_THIS, 9458021, Imessage, ""); 
                        lsttmpli = llCSV2List(Imessage);
                        agentsInTranslation = [];
                        for (w = 0; w < llGetListLength(lsttmpli); w += 4)
                        {
                            agentsInTranslation = (agentsInTranslation=[]) + agentsInTranslation + [llList2Key(lsttmpli, w), llList2String(lsttmpli, w + 1), llList2Integer(lsttmpli, w + 2), llList2Integer(lsttmpli, w + 3)];
                        }
                    }
                }
                else if (ImessageType == 1003)
                {
                    //Incoming agentsInTranslation dump from Slave
                    lsttmpli = llCSV2List(Imessage);
                    for (w = 0; w < llGetListLength(lsttmpli); w += 4)
                    {
                        addAgent(llList2Key(lsttmpli, w), llList2String(lsttmpli, w + 1), llList2Integer(lsttmpli, w + 2));
                    }
                }
                else if (ImessageType == 1004)
                {
                    //Incoming Preferences
                    options = Imessage;
                    lsttmpli = llCSV2List(options);
                    showTranslation = llList2Integer(lsttmpli, 0);
                    tranObjects = llList2Integer(lsttmpli, 1);
                    autoLanguage = llList2Integer(lsttmpli, 2);
                    llMessageLinked(LINK_THIS, 3342977, Imessage, ""); 
                }
            }           
            return;
        }
        //Translator Engine Code
        if ((llToLower(message) == "translator") && (isMaster > 0))
        {
            llMessageLinked(LINK_THIS, 2540664, message, id);
            return;
        }
        if ((!enabled) && (isMaster == 1)) return;
        if (!tranObjects)
        {
            if (llGetAgentSize(id) != ZERO_VECTOR) return;
        }
        lstliPos = llListFindList(agentsInTranslation, [id]);
        if (lstliPos >= 0)
        {           
            spkrLan = llList2String(agentsInTranslation, lstliPos + 1);
        }
        else
        {
            spkrLan = addNewAgent(id);
        }
        if (spkrLan == "xx") return;  //Agent Opt-Out
       
        llMessageLinked(LINK_ALL_CHILDREN, 6634934, (string)<1, 1, 0>, "");
        //===============================
        //Formulate Translation Requests
        //===============================
        for (w = 0; w < llGetListLength(agentsInTranslation); w += 4)
        {
            //Loop through translation group and do appropriate translations as needed
            recepID = llList2Integer(agentsInTranslation, w + 3);
            recepLan =  checkLanguage(llList2Key(agentsInTranslation, w + 1));
            if ((spkrLan != recepLan) && (recepLan != "") && (recepLan != "xx"))
            {
                lanpair = spkrLan + "|" + recepLan;
                lstliPos = llListFindList(translationCache, [lanpair]);
                if (lstliPos < 0)
                {
                  translationCache = (translationCache=[]) + translationCache + [lanpair, recepID];
                }
                else
                {
                  translationCache = llListReplaceList(translationCache, [llList2String(translationCache, lstliPos + 1) + "@" + (string)recepID], lstliPos + 1, lstliPos + 1);
                }
            }
        }
        //Process Requests
        if (llGetListLength(translationCache) > 0)
        {
            for (w = 0; w < llGetListLength(translationCache); w += 2)
            {
                //====================================
                //Translation
                //====================================
                //Forumulate and Send Translation Request
                lanpair = "|" + llList2String(llParseStringKeepNulls(llList2String(translationCache, w), ["|"],[]), 1);
                checkThrottle(0, llEscapeURL(message) + "&langpair=" + llEscapeURL(lanpair), [llGetTime(), id , llList2String(translationCache, w + 1), llList2String(translationCache, w)]);
            }
        }
        else
            spkrLan = "";
        //====================================
        //Language Detection
        //====================================
        if (llGetAgentSize(id) != ZERO_VECTOR) //llList2Key(llGetObjectDetails(id, [OBJECT_CREATOR]), 0) == NULL_KEY)
        {
            if (((spkrLan == "") || (llList2Integer(agentsInTranslation, llListFindList(agentsInTranslation, [id]) + 2) == TRUE)) || (isMaster == 2))
            {
                //Forumulate and Send Language Detect Request
                checkThrottle(1, llEscapeURL(message), [llGetTime(), id]);
            }     
        }
    }
   
    http_response(key request_id, integer status, list metadata, string body)
    {
        string  htttmpStr;
        if (status != 200)
        {
            //llOwnerSay("WWW Error:" + (string)status);
            llMessageLinked(LINK_ALL_CHILDREN, 6634934, (string)<1, 0, 0>, "");
            //llOwnerSay(body);
            return;
        }
        //Process Resonse Code
        htttmpStr = llGetSubString(body, llSubStringIndex(body, "\"responseStatus\":"), -1);
        status = (integer)llGetSubString(htttmpStr, 17, llSubStringIndex(htttmpStr, "}") - 1);
        if (status != 200)
        {
            //llOwnerSay("Language Server Returned Error Code: " + (string)status);
            //llOwnerSay(body);
            llMessageLinked(LINK_ALL_CHILDREN, 6634934, (string)<1, 0, 0>, "");
            return;
        }
        llMessageLinked(LINK_ALL_CHILDREN, 6634934, (string)<0, 0, 1>, "");
        llMessageLinked(LINK_THIS, 345149624, body, request_id);
    }
    timer()
    {
        llSetTimerEvent(0.0);  // timer reset
        integer r;
        string  tmrtmpStr;
        list    tmrnewli;
        integer translatorCount = llGetListLength(translators)/2;
        if (isInitialized == FALSE)
        {
            enabled = TRUE;
            listenID = llListen(0, "", "", "");
            llListen(777, "", NULL_KEY, "");
            llMessageLinked(LINK_THIS, 6877259, (string)enabled, NULL_KEY);
            isInitialized = TRUE;
        }
        llMessageLinked(LINK_THIS, 94558323, llList2CSV(agentsInTranslation), "");
        if (isMaster > 0)
        {
            for (r = 0; r < llGetListLength(agentsInTranslation); r += 4)
            {
                tmrtmpStr = llList2String(llGetObjectDetails(llList2Key(agentsInTranslation, r), [OBJECT_POS]), 0);
                if ((llVecDist(llGetPos(), (vector)tmrtmpStr) <= 20.0) && (tmrtmpStr != ""))
                {
                    tmrnewli = (tmrnewli=[]) + tmrnewli + llList2List(agentsInTranslation, r, r + 3);
                }
            }
            agentsInTranslation = tmrnewli;
            if ((llGetUnixTime() - lastHeartBeat) >= 5)
            {
                //Send heartbeat
                sendHeartbeat();
                lastHeartBeat = llGetUnixTime();
            }
        }
        else
        {
            if ((llGetUnixTime() - lastHeartBeat) >= `0 + llGetListLength(agentsInTranslation)*2 + llPow(translatorCount, 1.4) + translatorCount + ((1-llGetRegionTimeDilation()) * 5))
            {
                //Send heartbeat
                sendHeartbeat();
                lastHeartBeat = llGetUnixTime();
            }
        }
        //turn on and off scanner
        if ((autoLanguage) && isMaster > 0)
        {
            llSensor("", NULL_KEY, AGENT, 20.0, PI);
         }
         }
        llSetTimerEvent(4.0); // restart timer
        //llSetTimerEvent(4 + ((1-llGetRegionTimeDilation()) * 5));
     }
     }
}
}


</lsl>
</lsl>

Latest revision as of 03:36, 6 August 2010

Bienvenid@

Hola, soy Perry Mizin y este será mi humilde intento de contribución al proyecto "Traductor Universal de Google" creado por Hank Ramos.

El siguiente código fué originálmente creado por Hank Ramos, empezaré modificando algunas funciones a mí manera... No ós riais

Welcome

Hello, I am Perry Mizin and this will be my humble try to contribute with the project "Universal Google Translator" created by Hank Ramos.

The next code was originally created by Hank Ramos, I will start modifiying some functions on my way... Don´t laugh


OK

Bueno, despues de respiñar todo lo que pude, creo que el uso de memoria y la velocidad están prácticamente igual qué en la versión original pero bueno... en la variedad está el gusto no? Ya he probado un poco el código, y parece que funciona aunque estoy teniendo algunos problemas... Por ejemplo creo que el sistema de traduccion no funciona corréctamente, y no me refiero al sistema de traduccion de Google (en mi opinion, si no es el mejor, es uno de los mejores del mundo), sino a que aún queda mucho trabajo por hacer en el script...

El siguiente paso sera intentar dividir el script en dos, o si es posible en tres para repartir el uso de memoria. Tambien me gustaria probar un truco que uso a menudo para traducir páginas en un idioma que no entiendo, lo que hago es que en vez de traducir diréctamente al español, primero se traduce a inglés, y luego desde inglés al español. Parece una tontería y un gasto innecesario, pero si lo hago es porque así suelo entender mejor las traducciones. Quiero por un lado el sistema de comunicacion y evaluacion entre traductores, y por otro el sistema de traduccion entre avatares, ¿es muy dificil? no sé ya lo veremos...

Well, after saving as much as I could, I think the memory usage and the speed are technically the same as in the original script, but well, in the variety is the taste, isnt it?. I have tested a bit the code above already, and it seems to work altought i´m having some problems... For instance i think the translation system is not working properly, and i dont mean the Google´s translation system (in my opinion, if is not the best, one of the bests), but that there is still much work to do in the script...

The next step will be to try to divide the script in 2, or 3 if is possible, so we can spread the memory usage. Also I would like to test a trick i use often for to translate languages that i dont understand, what I do first is to translate that language into English, and then from English to Spanish, it seems a nonsense and unnecesary waste, but if i do it is becouse so i usually understand the translations better. I want by one part the translators communications and evaluation system, and by other the translation system between avatars, is it very difficult? I don´t know , we will see...


Es dificil... me está costando pero ya veremos... Its difficult... i am struggling but we will see...

chu chu chu


De Güatemala a Güatepeor, Sin comentarios...

From Güatebad to Güateworse, No comments...

Buscando en Internet he encontrado este API de Yahoo comprobador de ortografía, aunque creo que por ahora sólo soporta el lenguage inglés pero sería interesante añadirlo al proyecto

Searching on the web I crossed in my way with this spell checker Yahoo´s API , I think that it only supports English language by now althought it would be interesting to add it to the project


Estoy probando el comprobador de deletreo de Yahoo aunque la verdad es que no estoy teniendo buenos resultados, parece que Google es mucho más rapido y necesito corregir antes de traducir. También estoy intentando solucionar el error que aparece con el símbolo (apostrofe) ´ en las frases con genitivo sajon traducidas al inglés y tampoco doy con la tecla... Ya que esto me está dando muchos dolores de cabeza quizás deje el proyecto en standby hasta después de navidades.

I am testing the Yahoo´s spell checker althought to be honest I´m not having good success, it seems Google is much faster and I need to correct before translate. Also I am triying to fix the error showed in the phrases translated to English with the saxons genitive apostrophe ´ and still triying and triying. As this is driving me nuts, maybe I will leave the project in standby until new year.



ESTO ES EL TRADUCTOR "un lío" por ahora... Necesito rehacer algunas cosas

THIS IS THE TRANSLATOR "mess" by now... I need to redo some things THE CODE BELOW IS WORKING AND BEING TESTED

THIS IS AN ALPHA VERSION OF THE PERRYSONAL TRANSLATOR... NOTHING MORE TO SAY

Menu <lsl> //Mod Made in Perry Mizin //This is the interface, or menu-system of the translator. //Menu System //Copyright 2006-2009 by Hank Ramos //Variables integer randomDialogChannel; //Options integer enabled = TRUE; integer isShowTran = FALSE; integer tranObjects = TRUE; //Functions showMainMenu(key id) { list buttonList = []; string dialogMsg = "Options Menu."; if (id == llGetOwner()) { if (enabled) { buttonList = (buttonList=[]) + buttonList + ["Turn OFF"]; } else { buttonList = (buttonList=[]) + buttonList + ["Turn ON"]; } if (isShowTran) { buttonList = (buttonList=[]) + buttonList + ["Echo OFF"]; } else { buttonList = (buttonList=[]) + buttonList + ["Echo ON"]; } buttonList = (buttonList=[]) + buttonList + ["RESET"]; dialogMsg = (dialogMsg="") + dialogMsg + "\nECHO: show translations of your chat sent to others."; if (tranObjects) { buttonList = (buttonList=[]) + buttonList + ["Objects OFF"]; } else { buttonList = (buttonList=[]) + buttonList + ["Objects ON"]; } dialogMsg = (dialogMsg="") + dialogMsg + "\nOBJECTS: translate chat of scripted objects"; } llDialog(id, dialogMsg, buttonList, randomDialogChannel); } processListen(string name, key id, string message) { if (id == llGetOwner()) { else if (message == "Turn ON") { enabled = TRUE; llMessageLinked(LINK_THIS, 8439932,"enable", id); } else if (message == "Turn OFF") { enabled = FALSE; llMessageLinked(LINK_THIS, 8439932,"disable", id); } else if (message == "Echo ON") { isShowTran = TRUE; llMessageLinked(LINK_THIS, 8872932,"echon", id); } else if (message == "Echo OFF") { isShowTran = FALSE; llMessageLinked(LINK_THIS, 8872932,"echoff", id); } else if (message == "Objects OFF") { tranObjects = FALSE; llMessageLinked(LINK_THIS, 8439742,"objoff", id); } else if (message == "Objects ON") { tranObjects = TRUE; llMessageLinked(LINK_THIS, 8439742,"objon", id); } else if (message == "RESET") { llResetOtherScript("agents"); llResetOtherScript("form"); llResetOtherScript("trans"); llResetOtherScript("list"); llResetOtherScript("lan"); llOwnerSay("All Scripts are Resetted now..."); llResetScript(); } } } // default { state_entry() { llOwnerSay("Welcome to the Perrysonal Translator, probably the worst FREE translator in SL!"); randomDialogChannel = (integer)llFrand(2147483647); llMessageLinked(LINK_SET, 7563297, "XTRNSL", NULL_KEY); //Other Setup llListen(randomDialogChannel, "", NULL_KEY, ""); showMainMenu(llGetOwner()); } on_rez(integer start_param)

   {
       // Reset script when the object is rezzed
       llResetScript();
   }

touch_start(integer total_number) { if(llDetectedKey(0) == llGetOwner()) { showMainMenu(llGetOwner()); } } listen(integer channel, string name, key id, string message) { processListen(name,id,message); } }


</lsl>

Listener <lsl> // www.lsleditor.org by Alphons van der Heijden (SL: Alphons Jano) //(Mod made in Perry Mizin) I want to succeed with this translator... ;) call me day or night //Universal Translator //LSL Script copyright 2006-2009 by Hank Ramos //Translation Web Services powered by Google //listener integer tranObjects = TRUE; integer enabled = TRUE; key restricted; key owner; // default { state_entry() { owner = llGetOwner(); llListen(0,"",NULL_KEY,""); }

   on_rez(integer start_param)
   {
       // Reset script when the object is rezzed
       llResetScript();
   }

link_message(integer sender_num, integer num, string str, key id) { if (num == 8439932) { if(str=="enable") { enabled = TRUE; } else if(str=="disable") { enabled = FALSE; } } if (num == 8439742) { if(str=="objon") { tranObjects = TRUE; } else if(str=="objoff") { tranObjects = FALSE; } } } listen(integer channel, string name, key id, string message) { if(channel==PUBLIC_CHANNEL) { if (!enabled) { return; } if (restricted==id) { llSetTimerEvent(0.0); restricted = id; llSetTimerEvent(0.7); return; } if (!tranObjects) { if (llGetAgentSize(id) == ZERO_VECTOR) { return; } } if (llStringLength(message) < 12) { llMessageLinked(LINK_THIS,98745920,message,id); } else { llMessageLinked(LINK_THIS,7686795,message,id); llMessageLinked(LINK_THIS,98745920,message,id); } llSetTimerEvent(0.7); restricted = id; } } timer() { restricted = NULL_KEY; llSetTimerEvent(0.0); } }

</lsl>


agentsinTranslation <lsl> //(Mod made in Perry Mizin) //Universal Translator //Version 1.9.0 //December 25, 2009 //LSL Script copyright 2006-2009 by Hank Ramos //Translation Web Services powered by Google key owner; key speaker; key sid; list agentsInTranslation; list tmrli; list newList; integer listenID; integer tmpavliPos; integer ownerliPos; vector tmrVct; string actlan; string tmplan; string spkLan; string SEPARATOR = "|%&|"; string mylanguage; string checkLanguage(string chklantmpStr) { if (chklantmpStr == "") { chklantmpStr = "en"; } else if (chklantmpStr == "und") { chklantmpStr = "el"; } else if (chklantmpStr == "Gh") { chklantmpStr = "en"; } if (llGetSubString(chklantmpStr, 0, 1) == "zh") { chklantmpStr = "zh-CN"; } else { chklantmpStr = llGetSubString(chklantmpStr, 0, 1); } return chklantmpStr; } string addNewAgent(key newavid) { string speakerLan; if (llGetAgentSize(newavid) == ZERO_VECTOR) { speakerLan = "en"; } else { speakerLan = checkLanguage(llGetAgentLanguage(newavid)); if (speakerLan == "") { speakerLan = "en"; addAgent(newavid, speakerLan, 0); } else { addAgent(newavid, speakerLan, 0); } } return speakerLan; } key getAgentKey(integer agentID) { if(~llListFindList(agentsInTranslation, (list)agentID)) { integer gkliPos = llListFindList(agentsInTranslation, (list)agentID); return llList2Key(agentsInTranslation, gkliPos - 4); } else { return NULL_KEY; } } string List2TypeSep(list input2) { integer w; list output2; for (w = 0; w < llGetListLength(input2); w++) { output2 += [llGetListEntryType(input2, w)] + llList2List(input2, w, w); } return llDumpList2String(output2, SEPARATOR); } list TypeSep2List(string inputstring) { integer v; list input; list output; input = llParseString2List(inputstring, [SEPARATOR], []); for (v = 0; v < llGetListLength(input); v += 2) { if (llList2Integer(input, v) == TYPE_INTEGER) output += (integer)llList2String(input, v + 1); else if (llList2Integer(input, v) == TYPE_FLOAT) output += (float)llList2String(input, v + 1); else if (llList2Integer(input, v) == TYPE_STRING) output += llList2String(input, v + 1); else if (llList2Integer(input, v) == TYPE_KEY) output += (key)llList2String(input, v + 1); } return output; } addAgent(key avid, string avlan, integer chklan) { integer avliPos; integer idNum; if (~llListFindList(agentsInTranslation, (list)avid)) { avliPos = llListFindList(agentsInTranslation, (list)avid); agentsInTranslation = llListReplaceList(agentsInTranslation, [avlan, avlan, chklan], avliPos + 1, avliPos + 3); } else { @at; idNum = llRound(llFrand(2000000)) + 1; if(~llListFindList(agentsInTranslation, (list)idNum)) { jump at; } agentsInTranslation = (agentsInTranslation=[]) + agentsInTranslation + [avid, avlan, avlan, chklan, idNum]; } } // default { state_entry() { owner = llGetOwner(); listenID = llListen(0, "", "", ""); mylanguage = llGetAgentLanguage(owner); if (llStringLength(mylanguage) < 1) { mylanguage = "en"; } if(~llListFindList(agentsInTranslation, (list)owner)) { ownerliPos = llListFindList(agentsInTranslation, (list)owner); agentsInTranslation = llListReplaceList(agentsInTranslation, [mylanguage] , ownerliPos + 1, ownerliPos + 1); } else { agentsInTranslation = (agentsInTranslation=[]) + agentsInTranslation + [owner, mylanguage, mylanguage, 0, llRound(llFrand(2000000)) + 1]; } llSetTimerEvent(1.0); } link_message(integer sender_num, integer num, string lstr, key lid) { if (num == 6349160) { speaker = lid; spkLan = lstr; if (~llListFindList(agentsInTranslation, (list)speaker)) { tmpavliPos = llListFindList(agentsInTranslation, (list)speaker); actlan = llList2String(agentsInTranslation, tmpavliPos + 1); tmplan = llList2String(agentsInTranslation, tmpavliPos + 2); if (llList2Integer(agentsInTranslation, tmpavliPos + 3) >= 2) { // if anyone speaks on any different language 3 times in a row addAgent(lid, lstr, 0); } if (actlan == lstr) { // reset language checker for speaker agentsInTranslation = llListReplaceList(agentsInTranslation, [actlan, 0], tmpavliPos + 2, tmpavliPos + 3); } else { if (lstr == tmplan) { // if language of speaker is not the same as detected language agentsInTranslation = llListReplaceList(agentsInTranslation,[llList2Integer(agentsInTranslation,tmpavliPos + 3) + 1] , tmpavliPos + 3, tmpavliPos + 3); } else { agentsInTranslation = llListReplaceList(agentsInTranslation,[lstr, 0] , tmpavliPos + 2, tmpavliPos + 3); } } } } if (num == 9876754) { llMessageLinked(LINK_THIS,7659759,List2TypeSep(agentsInTranslation),NULL_KEY); } } listen(integer channel, string name, key id, string message) { if(~llListFindList(agentsInTranslation, (list)id)) { } else { addNewAgent(id); } } sensor(integer num_detected) { integer s; for (s = 0; s < num_detected; s += 1) { sid = llDetectedKey(s); if (~llListFindList(agentsInTranslation, (list)sid)) { } else { addNewAgent(sid); } } } no_sensor() { } timer() { llSetTimerEvent(0.0); integer r; for (r = 0; r < llGetListLength(agentsInTranslation); r += 5) { tmrli = llGetObjectDetails(llList2Key(agentsInTranslation, r), [OBJECT_POS]); tmrVct = llList2Vector(tmrli, 0); if (tmrVct == ZERO_VECTOR) { } else { if (llVecDist(llGetPos(), tmrVct) <= 20.0) { newList = (newList=[]) + newList + llList2List(agentsInTranslation, r, r + 4); } } } agentsInTranslation = newList; newList = []; llSensor("",NULL_KEY,AGENT,20.0,PI); llSetTimerEvent(6.0); // restart timer } } </lsl>


DetectLanguage <lsl> //(Mod made in Perry Mizin) //Universal Translator //Version 1.9.0 //December 25, 2009 //LSL Script copyright 2006-2009 by Hank Ramos //Translation Web Services powered by Google key dtcValue; key speakerID; string htttmpStr; list tempDetections; list newList; float timeElapsed; integer tmpliPos; integer contains(string haystack, string needle) // http://wiki.secondlife.com/wiki/llSubStringIndex { return ~llSubStringIndex(haystack, needle); } DetectLanguage(string dtcmsg, key dtcid) { dtcValue = llHTTPRequest("http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=" + llEscapeURL(dtcmsg), [HTTP_METHOD, "GET", HTTP_MIMETYPE, "plain/text;charset=utf-8"], " "); if (dtcValue != NULL_KEY) { tempDetections = (tempDetections=[]) + tempDetections + [dtcValue, dtcid, llGetTime()]; } else { llSleep(10.0); // Something has gone horribly wrong, sleep 10 seconds clear throttle } } // default { state_entry() { llSetTimerEvent(5.0); } link_message(integer sender, integer num, string msg, key id) { if (num == 7686795) { DetectLanguage(msg, id); } } http_response(key request_id, integer status, list metadata, string body) { // Process Response Code if (~llListFindList(tempDetections, (list)request_id)) { // Language Detection tmpliPos = llListFindList(tempDetections, (list)request_id); speakerID = llList2Key(tempDetections, tmpliPos + 1); tempDetections = llDeleteSubList(tempDetections, tmpliPos, tmpliPos + 2); htttmpStr = llToLower(llGetSubString(body, llSubStringIndex(body, "{\"language\":\"") + 13, llSubStringIndex(body, "\",\"isReliable\":") - 1)); if (contains(htttmpStr, "err") == 0 && contains(htttmpStr, "unn") == 0) { // We Trust the Google system, the Google´s guys are good and I am sure they will keep improving :-) if(llStringLength(htttmpStr) <= 3) { llMessageLinked(LINK_THIS,6349160,htttmpStr,speakerID); } } } } timer() { llSetTimerEvent(0.0); integer r; integer TliLen = llGetListLength(tempDetections); for (r = 0; r < TliLen; r += 3) { timeElapsed = llGetTime() - llList2Float(tempDetections, r + 2); if (timeElapsed > 10.0) { newList = (newList=[]) + newList + llList2List(tempDetections, r, r + 2); } } tempDetections = newList; newList = []; llSetTimerEvent(5.0); } }

</lsl>


Formulator <lsl> //(Mod made in Perry Mizin) //Universal Translator //Version 1.9.0 //December 25, 2009 //LSL Script copyright 2006-2009 by Hank Ramos //Translation Web Services powered by Google //Formulator Script list agentsInTranslation; list txli; list translationCache; list tomali; string SEPARATOR = "|%&|"; string recepientLanguage; string speakerLanguage; string txmessage; string spkrLan; string recep; string recepLan; string lanpair; string request; integer M = 1; integer rxID; integer recepID; integer lstliPos; integer lstliPos2; integer txPos; integer lint; key recepientID; float cacheTime; sendIM(key imid, string imstr) { if (M == 8) { llMessageLinked(LINK_ALL_OTHERS,2334420,imstr,imid); M = 1; } else if (M == 7) { llMessageLinked(LINK_ALL_OTHERS,2334430,imstr,imid); M = 8; } else if (M == 6) { llMessageLinked(LINK_ALL_OTHERS,2334440,imstr,imid); M = 7; } else if (M == 5) { llMessageLinked(LINK_ALL_OTHERS,2334450,imstr,imid); M = 6; } else if (M == 4) { llMessageLinked(LINK_ALL_OTHERS,2334460,imstr,imid); M = 5; } else if (M == 3) { llMessageLinked(LINK_ALL_OTHERS,2334470,imstr,imid); M = 4; } else if (M == 2) { llMessageLinked(LINK_ALL_OTHERS,2334480,imstr,imid); M = 3; } else if (M == 1) { llMessageLinked(LINK_ALL_OTHERS,2334490,imstr,imid); M = 2; } } key getAgentKey(integer agentID) { if(~llListFindList(agentsInTranslation, (list)agentID)) { integer gkliPos = llListFindList(agentsInTranslation, (list)agentID); return llList2Key(agentsInTranslation, gkliPos - 4); } else { return NULL_KEY; } } list TypeSep2List(string inputstring) { integer h; list input; list output; input = llParseString2List(inputstring, [SEPARATOR], []); for (h = 0; h < llGetListLength(input); h += 2) { if (llList2Integer(input, h) == TYPE_INTEGER) output += (integer)llList2String(input, h + 1); else if (llList2Integer(input, h) == TYPE_FLOAT) output += (float)llList2String(input, h + 1); else if (llList2Integer(input, h) == TYPE_STRING) output += llList2String(input, h + 1); else if (llList2Integer(input, h) == TYPE_KEY) output += (key)llList2String(input, h + 1); } return output; } string List2TypeSep(list input2) { integer l; list output2; for (l = 0; l < llGetListLength(input2); l++) { output2 += [llGetListEntryType(input2, l)] + llList2List(input2, l, l); } return llDumpList2String(output2, SEPARATOR); } // default { state_entry() { llSetTimerEvent(1.0); } link_message(integer sender_num, integer num, string lstr, key id) { if (num == 7659759) { agentsInTranslation = TypeSep2List(lstr); } if (num == 9827491) { txli = TypeSep2List(lstr); rxID = llList2Integer(txli,0); speakerLanguage = llList2String(txli,1); txmessage = llList2String(txli,2); lint = llListFindList(agentsInTranslation, (list)rxID); recepientLanguage = llList2String(agentsInTranslation, lint - 3); recepientID = getAgentKey(rxID); if (recepientID != NULL_KEY) { if (recepientLanguage == speakerLanguage) { } else { sendIM(recepientID,txmessage); } } } if (num == 98745920) { txPos = llListFindList(agentsInTranslation, (list)id); cacheTime = llGetTime(); if(id==llGetOwner()) { integer v; integer agentslilen = llGetListLength(agentsInTranslation); for (v = 0; v < agentslilen; v += 5) { spkrLan = llList2String(agentsInTranslation, txPos + 1); recepID = llList2Integer(agentsInTranslation, v + 4); recepLan = llList2String(agentsInTranslation, v + 1); if (spkrLan == recepLan) { } else { lanpair = spkrLan + "|" + recepLan; if (~llListFindList(translationCache, (list)lanpair)) { lstliPos = llListFindList(translationCache, (list)lanpair); translationCache = llListReplaceList(translationCache, [llList2String(translationCache, lstliPos + 1) + "@" + (string)recepID], lstliPos + 1, lstliPos + 1); } else { translationCache = (translationCache=[]) + translationCache + [lanpair, recepID, cacheTime]; } } } if (translationCache != []) { integer w; for (w = 0; w < llGetListLength(translationCache); w += 3) { lanpair = llList2String(translationCache, w); recep = llList2String(translationCache, w + 1); tomali = [lstr, lanpair, recep]; request = List2TypeSep(tomali); llMessageLinked(LINK_THIS,2346017,request,id); } } } else { lstliPos2 = llListFindList(agentsInTranslation, (list)llGetOwner()); if (~llListFindList(agentsInTranslation, (list)id)) { spkrLan = llList2String(agentsInTranslation, txPos + 1); recepID = llList2Integer(agentsInTranslation, lstliPos2 + 4); recepLan = llList2String(agentsInTranslation, lstliPos2 + 1); if (spkrLan == recepLan) { } else { lanpair = spkrLan + "|" + recepLan; if (~llListFindList(translationCache, (list)lanpair)) { lstliPos = llListFindList(translationCache, (list)lanpair); translationCache = llListReplaceList(translationCache, [llList2String(translationCache, lstliPos + 1) + "@" + (string)recepID], lstliPos + 1, lstliPos + 1); } else { translationCache = (translationCache=[]) + translationCache + [ lanpair, recepID, cacheTime ]; } } } if (translationCache != []) { // Process Requests tomali = [lstr, lanpair, recepID]; request = List2TypeSep(tomali); llMessageLinked(LINK_THIS,2346017,request,id); } } } } timer() { llSetTimerEvent(0.0); float timeElapsed; list newList; integer r; for (r = 0; r < llGetListLength(translationCache); r += 3) { timeElapsed = llGetTime() - llList2Float(translationCache, r + 2); if (timeElapsed < 10.0) { newList = (newList=[]) + newList + llList2List(translationCache, r, r + 2); } } translationCache = newList; newList = []; llMessageLinked(LINK_THIS,9876754,"",NULL_KEY); llSetTimerEvent(12.0); } } </lsl>

Translator <lsl> //(Mod made in Perry Mizin) //Universal Translator //Version 1.9.0 //December 25, 2009 //LSL Script copyright 2006-2009 by Hank Ramos //Translation Web Services powered by Google list paramtmpli; list recepientList; list requestedTranslations; list forli; list txli; list txli2; list lkli; string SEPARATOR = "|%&|"; string recepientLanguage; string languagePair; string speakerName; string speakerLanguage; string translatedText; string lantmpStr; string lmsg; string llan; string sendim; string request; string llid; key speakerID; key returnValue; key tid; integer tranObjects = TRUE; integer isMaster = 1; integer enabled = FALSE; integer httliPos; integer lmPos; integer httbusy; Translate(string chkmsg, list chkli) { returnValue = llHTTPRequest("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" + llEscapeURL(chkmsg) + "&langpair=" + llList2String(chkli,2), [HTTP_METHOD, "GET", HTTP_MIMETYPE, "plain/text;charset=utf-8"], ""); if (returnValue != NULL_KEY) { requestedTranslations = (requestedTranslations=[]) + requestedTranslations + [returnValue]; requestedTranslations = (requestedTranslations=[]) + requestedTranslations + chkli; } else { llOwnerSay("ERROR ERROR ERROR ERROR ERRORR ERROOOORRRRR"); llOwnerSay("All Go!"); llSleep(25.0); } } string List2TypeSep(list input) { integer v; list output; for (v = 0; v < llGetListLength(input); v++) { output += [llGetListEntryType(input, v)] + llList2List(input, v, v); } return llDumpList2String(output, SEPARATOR); } list TypeSep2List(string inputstring) { integer w; list input2; list output2; input2 = llParseString2List(inputstring, [SEPARATOR], []); for (w = 0; w < llGetListLength(input2); w += 2) { if (llList2Integer(input2, w) == TYPE_INTEGER) output2 += (integer)llList2String(input2, w + 1); else if (llList2Integer(input2, w) == TYPE_FLOAT) output2 += (float)llList2String(input2, w + 1); else if (llList2Integer(input2, w) == TYPE_STRING) output2 += llList2String(input2, w + 1); else if (llList2Integer(input2, w) == TYPE_KEY) output2 += (key)llList2String(input2, w + 1); } return output2; } // default { state_entry() { httbusy=FALSE; llSetTimerEvent(1.0); } link_message(integer sender_num, integer num, string lstr, key lid) { if (num == 2346017) { if(httbusy==FALSE) { httbusy = TRUE; if (~llListFindList(txli2, (list)lstr)) { lmPos = llListFindList(txli2, (list)lstr); txli2 = llDeleteSubList(txli2, lmPos, lmPos + 1); txli = TypeSep2List(lstr); lmsg = llList2String(txli,0); llan = llList2String(txli,1); llid = llList2String(txli,2); lkli = [ llGetTime(), lid, llan, llid ]; Translate(lmsg,lkli); } else { txli = TypeSep2List(lstr); lmsg = llList2String(txli,0); llan = llList2String(txli,1); llid = llList2String(txli,2); lkli = [ llGetTime(), lid, llan, llid ]; Translate(lmsg,lkli); } } else { if (~llListFindList(txli2, (list)lstr)) { } else { txli2 = (txli2=[]) + txli2 + [lstr]; txli2 = (txli2=[]) + txli2 + [lid]; } } } } http_response(key request_id, integer status, list metadata, string body) { // Process Response Code if (~llListFindList(requestedTranslations, (list)request_id)) { // Translation httliPos = llListFindList(requestedTranslations, (list)request_id); speakerID = llList2Key(requestedTranslations, httliPos + 2); speakerName = llKey2Name(speakerID); if (llStringLength(speakerName) < 3) { speakerName = llList2String(llGetObjectDetails(speakerID, [OBJECT_NAME]), 0); } recepientList = llParseString2List(llList2String(requestedTranslations, httliPos + 4),["@"],[]); paramtmpli = llParseStringKeepNulls(llList2String(requestedTranslations, httliPos + 3),["|"],[]); speakerLanguage = llList2String(paramtmpli, 0); recepientLanguage = llList2String(paramtmpli, 1); languagePair = llDumpList2String(paramtmpli, ">>"); // Perform Text Cleanup translatedText = llGetSubString(body, llSubStringIndex(body, "{\"translatedText\":\"") + 18, llSubStringIndex(body, "}, \"responseDetails\"") -1); // Reverse order if Recepient Language is Hebrew or Arabic if ((recepientLanguage == "iw") || (recepientLanguage == "ar")) { lantmpStr = ""; integer q; for(q = llStringLength(translatedText);q >= 0; q--) { lantmpStr = (lantmpStr="") + lantmpStr + llGetSubString(translatedText, q, q); } translatedText = lantmpStr; } lantmpStr = speakerName + "(" + languagePair + "): " + translatedText; integer z; integer reclen = llGetListLength(recepientList); for (z = 0; z < reclen; z += 1) { forli = [llList2Integer(recepientList, z), speakerLanguage , lantmpStr]; sendim = List2TypeSep(forli); llMessageLinked(LINK_THIS,9827491,sendim,NULL_KEY); } requestedTranslations = llDeleteSubList(requestedTranslations, httliPos, httliPos + 4); httbusy = FALSE; llSetTimerEvent(1.0); } } timer() { llSetTimerEvent(0.0); if(txli2 != []) { integer m; integer lleng = llGetListLength(txli2); for (m = 0; m < lleng; m += 2) { request = llList2String(txli2, m); tid = llList2Key(txli2, m + 1); llMessageLinked(LINK_THIS,2346017,request,tid); } } float timeElapsed; list newList; integer r; for (r = 0; r < llGetListLength(requestedTranslations); r += 6) { timeElapsed = llGetTime() - llList2Float(requestedTranslations, r + 1); if (timeElapsed < 20.0) { newList = (newList=[]) + newList + llList2List(requestedTranslations, r, r + 5); } } requestedTranslations = newList; newList = []; llSetTimerEvent(5.0); } } </lsl>

IM handler <lsl> // www.lsleditor.org by Alphons van der Heijden (SL: Alphons Jano) //(Mod made in Perry Mizin) I want to succeed with this translator... ;) call me day or night //Universal Translator //Version 1.9.0 //December 25, 2009 //LSL Script copyright 2006-2009 by Hank Ramos //Translation Web Services powered by Google integer echo; list escape=["\\u0026#39;" , "'" , "\\u003d" , "=" , "\\u0026amp;" , "&" , "\\u0026lt;" , "<" , "\\u0026gt;" , ">" , "\\u0026quot;" , "\""]; string Escape(string text) {

   integer i; string result;
   list t=llParseString2List(text,[],["\\u0026#39;","\\u003d","\\u0026amp;","\\u0026lt;","\\u0026gt;","\\u0026quot;"]);
   for(i=0;i<llGetListLength(t);i++)
   {
       integer ii=llListFindList(escape,[llList2String(t,i)]);
       if(ii!=-1)
       {
           t=llListReplaceList(t,[llList2String(escape,ii+1)],i,i);
       }
   }
   result=llDumpList2String(t,"");
   return result;

}

sendim(string mess, key target) {

   if (llGetAgentSize(target) == ZERO_VECTOR)
   { }
   else
   {
       llInstantMessage(target, llUnescapeURL(mess));
       if(echo==TRUE)
       {
           llOwnerSay(mess + " @" + llKey2Name(target));
       }
   }

}


default {

   state_entry()
   {
       echo=FALSE;
       llSleep(0.1);
   }
   link_message(integer sender_num, integer num, string str, key id)
   {
       if (num == 2334420)
       {
           sendim(Escape(str),id);
       }
       
       if (num == 8872932)
       {
           if(str=="echon")
           {
               echo=TRUE;
           }
           if(str=="echoff")
           {
               echo=FALSE;
           }
       }
   }

}

</lsl>