Difference between revisions of "User talk:Perry Mizin"

From Second Life Wiki
Jump to navigation Jump to search
Line 67: Line 67:
//Translation Web Services powered by Google
//Translation Web Services powered by Google
//Spell Checker Web Services powered by Yahoo
//Spell Checker Web Services powered by Yahoo
key owner;
list agentsInTranslation;
list agentsInTranslation;
integer isInitialized = FALSE;
integer isInitialized = FALSE;
Line 74: Line 75:
integer enabled = FALSE;
integer enabled = FALSE;
string SEPARATOR = "|%&|"; // for transmitting lists via linked messages
string SEPARATOR = "|%&|"; // for transmitting lists via linked messages
integer M = 1;
integer ShowTranslations = TRUE;
sendIM(key imid, string imstr)
{
    // llInstantMessage(key id , string message) causes the script to sleep for 2 seconds
    if (llGetAgentSize(imid) == ZERO_VECTOR)
    { }
    else
    {
        if (imid != llGetOwner())
        {
            llOwnerSay(imstr + " @" + llKey2Name(imid));  // llOwnerSay(string message) has no delay
        }
        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;
        }
    }
}


string checkLanguage(string chklantmpStr)
string checkLanguage(string chklantmpStr)
Line 212: Line 155:
}
}


string List2String(list input)
string List2TypeSep(list input) { // converts a list to a separated string with type information prepended to each item
{ // converts list to a string
    integer    i;
     return llDumpList2String(input, SEPARATOR);
    list        output;
 
    for (i = 0; i < llGetListLength(input); i++) {
        output += [llGetListEntryType(input, i)] + llList2List(input, i, i);
    }
   
     return llDumpList2String(output, SEPARATOR);
}
}


list String2List(string inputstring)
list TypeSep2List(string inputstring) { // converts a separated string created with List2TypeSep back to a list with the correct type information
{ // converts a separated string created with List2String back to a list
    integer    i;
     list output;
    list        input;
     output = llParseString2List(inputstring, [SEPARATOR], []);  
     list       output;
      
    input = llParseString2List(inputstring, [SEPARATOR], []);
 
    for (i = 0; i < llGetListLength(input); i += 2) {
        if (llList2Integer(input, i) == TYPE_INTEGER) output += (integer)llList2String(input, i + 1);
        else if (llList2Integer(input, i) == TYPE_FLOAT) output += (float)llList2String(input, i + 1);
        else if (llList2Integer(input, i) == TYPE_STRING) output += llList2String(input, i + 1);
        else if (llList2Integer(input, i) == TYPE_KEY) output += (key)llList2String(input, i + 1);
    }
   
     return output;
     return output;
}
}
Line 227: Line 186:
{
{
     state_entry()
     state_entry()
     {      
     {
        owner = llGetOwner();
         llSetTimerEvent(1.0);
         llSetTimerEvent(1.0);
     }
     }
   
 
     link_message(integer sender_num, integer num, string lstr, key lid)
     link_message(integer sender_num, integer num, string lstr, key lid)
     {
     {
         if (num == 9876754)
         if (num == 9876754)
         {
         {
             llMessageLinked(LINK_THIS,7659759,List2String(agentsInTranslation),NULL_KEY);
             llMessageLinked(LINK_THIS,7659759,List2TypeSep(agentsInTranslation),NULL_KEY);
         }
         }
         if (num == 9827491)
         if (num == 6349160)
         {
         {
            list txli;
 
key recepientID;
key txID;
integer rxID;
string recepientLanguage;
string speakerLanguage;
string txmessage;
txID = lid;
txli = String2List(lstr);
rxID = llList2Integer(txli,0)
speakerLanguage = llList2String(txli,1);
txmessage = llList2String(txli,2);           
recepientLanguage = llList2String(agentsInTranslation, llListFindList(agentsInTranslation, (list)txID) + 1);
recepientID = getAgentKey(rxID);
            if (recepientID != NULL_KEY)
            {
                if (recepientLanguage == speakerLanguage)
                { }
                else
                {
                    sendIM(lid,txmessage);
                }
            }
        }
        if (num == 6349160)
{
             key speaker;
             key speaker;
             string spkLan;
             string spkLan;
Line 294: Line 228:
                     }
                     }
                 }
                 }
             }          
             }
         }
         }
     }
     }
   
 
     sensor(integer num_detected)
     sensor(integer num_detected)
     {
     {
Line 318: Line 252:


     listen(integer channel, string name, key id, string message)
     listen(integer channel, string name, key id, string message)
     {      
     {
         if(~llListFindList(agentsInTranslation, (list)id))
         if(~llListFindList(agentsInTranslation, (list)id))
         { }
         { }
Line 331: Line 265:
         integer r;
         integer r;
         vector  tmrVct;
         vector  tmrVct;
        list tmrli;
         list  newList;
         list  newList;
         llSetTimerEvent(0.0);  // we better reset timer by way of precaution
         llSetTimerEvent(0.0);  // we better reset timer by way of precaution
         if (isInitialized == FALSE)
         if (isInitialized == FALSE)
{
        {
string mylanguage;
            string mylanguage;
             enabled = TRUE;
             enabled = TRUE;
             listenID = llListen(0, "", "", "");
             listenID = llListen(0, "", "", "");
             llMessageLinked(LINK_THIS, 6877259, (string)enabled, NULL_KEY);
             llMessageLinked(LINK_THIS, 6877259, (string)enabled, NULL_KEY);
             isInitialized = TRUE;
             isInitialized = TRUE;
mylanguage = llGetAgentLanguage(llGetOwner());
            mylanguage = llGetAgentLanguage(owner);
             if (llStringLength(mylanguage) < 1)
             if (llStringLength(mylanguage) < 1)
             {
             {
                 mylanguage = "en";
                 mylanguage = "en";
             }
             }
             if(~llListFindList(agentsInTranslation, (list)llGetOwner()))
             if(~llListFindList(agentsInTranslation, (list)owner))
             {
             {
integer ownerliPos;
                integer ownerliPos;
ownerliPos = llListFindList(agentsInTranslation, (list)llGetOwner());
                ownerliPos = llListFindList(agentsInTranslation, (list)owner);
                 agentsInTranslation = llListReplaceList(agentsInTranslation, [mylanguage] , ownerliPos + 1, ownerliPos + 1);
                 agentsInTranslation = llListReplaceList(agentsInTranslation, [mylanguage] , ownerliPos + 1, ownerliPos + 1);
             }
             }
             else
             else
             {
             {
                 agentsInTranslation = (agentsInTranslation=[]) + agentsInTranslation + [ llGetOwner() , mylanguage, mylanguage , 0 , llRound(llFrand(2000000)) + 1];
                 agentsInTranslation = (agentsInTranslation=[]) + agentsInTranslation + [ owner , mylanguage, mylanguage , 0 , llRound(llFrand(2000000)) + 1];
             }
             }
         }
         }
Line 360: Line 295:
             for (r = 0; r < llGetListLength(agentsInTranslation); r += 5)
             for (r = 0; r < llGetListLength(agentsInTranslation); r += 5)
             {
             {
                 tmrVct = llList2Vector(llGetObjectDetails(llList2Key(agentsInTranslation, r), [OBJECT_POS]), 0);
                 tmrli = llGetObjectDetails(llList2Key(agentsInTranslation, r), [OBJECT_POS]);
                 if (llVecDist(llGetPos(), tmrVct) <= 20.0)
                tmrVct = llList2Vector(tmrli, 0);
                 if (tmrVct == ZERO_VECTOR)
                {  }
                else
                 {
                 {
                     newList = (newList=[]) + newList + llList2List(agentsInTranslation, r, r + 4);
                     if (llVecDist(llGetPos(), tmrVct) <= 20.0)
                 }
                    {
                        newList = (newList=[]) + newList + llList2List(agentsInTranslation, r, r + 4);
                    }
                 }                  
             }
             }
             agentsInTranslation = newList;
             agentsInTranslation = newList;
             newList = [];
             newList = [];
         }
         }
         if ((autoLanguage) && isMaster > 0)
         if (autoLanguage == TRUE && isMaster > 0)
         {
         {
             llSensor("", NULL_KEY, AGENT, 20.0, PI);
             llSensor("", NULL_KEY, AGENT, 20.0, PI);
Line 398: Line 339:
list tempDetections;
list tempDetections;
list spellchecks;
list spellchecks;
string strReplace(string str, string search, string replace) {
    return llDumpList2String(llParseStringKeepNulls((str = "") + str, [search], []), replace);
}


integer contains(string haystack, string needle) // http://wiki.secondlife.com/wiki/llSubStringIndex
integer contains(string haystack, string needle) // http://wiki.secondlife.com/wiki/llSubStringIndex
{
{
return ~llSubStringIndex(haystack, needle);
    return ~llSubStringIndex(haystack, needle);
}
}


DetectLanguage(string dtcmsg, key dtcid)
DetectLanguage(string dtcmsg, key dtcid)
{
{
llSleep(0.2);
    llSleep(0.2);
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"], " ");
    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)
    if (dtcValue != NULL_KEY)
{
    {
tempDetections = (tempDetections=[]) + tempDetections + [ dtcValue, dtcid, llGetTime() ];
        tempDetections = (tempDetections=[]) + tempDetections + [ dtcValue, dtcid, llGetTime() ];
}
    }
else
    else
{
    {
llSleep(10.0); // Something has gone horribly wrong, sleep 10 seconds clear throttle
        llSleep(10.0); // Something has gone horribly wrong, sleep 10 seconds clear throttle
}
    }
}
}


CheckSpell(string splmsg, key splid)
CheckSpell(string splmsg, key splid)
{
{
splValue = llHTTPRequest("http://search.yahooapis.com/WebSearchService/V1/spellingSuggestion?appid=DNPjiabV34EOgXQ3kAu6.d7kf6v.JUGCn1bFUcSTFMSGCyCy_ALzbepYstlI7DrOGP0-&query=" + llEscapeURL(splmsg), [HTTP_METHOD, "GET", HTTP_MIMETYPE, "plain/text;charset=utf-8"], "");
    splValue = llHTTPRequest("http://search.yahooapis.com/WebSearchService/V1/spellingSuggestion?appid=DNPjiabV34EOgXQ3kAu6.d7kf6v.JUGCn1bFUcSTFMSGCyCy_ALzbepYstlI7DrOGP0-&query=" + llEscapeURL(splmsg), [HTTP_METHOD, "GET", HTTP_MIMETYPE, "plain/text;charset=utf-8"], "");
if (splValue != NULL_KEY)
    if (splValue != NULL_KEY)
{    // Translation
    {    // Translation
spellchecks = (spellchecks=[]) + spellchecks + [ splValue, splid, splmsg, llGetTime() ];
        spellchecks = (spellchecks=[]) + spellchecks + [ splValue, splid, strReplace(splmsg,",","^ñ^"), llGetTime() ];
}
    }
else
    else
{
    {
llSleep(10.0); // Something has gone horribly wrong, sleep 10 seconds clear throttle
        llSleep(10.0); // Something has gone horribly wrong, sleep 10 seconds clear throttle
}
    }
}
}


Line 434: Line 379:
default
default
{
{
state_entry()
    state_entry()
{
    {
llListen(0,"","","");
        llListen(0,"","","");
}
    }


listen(integer channel, string name, key id, string message)
    listen(integer channel, string name, key id, string message)
{
    {
if ((!enabled) && (isMaster == 1))
        if ((!enabled) && (isMaster == 1))
{
        {
return;
            return;
}
        }
if (!tranObjects)
        if (!tranObjects)
{
        {
if (llGetAgentSize(id) == ZERO_VECTOR)
            if (llGetAgentSize(id) == ZERO_VECTOR)
{
            {
return;
                return;
}
            }
else
            else
{
            {
if (SpellChecker == 1)
                if (SpellChecker == 1)
{
                {
CheckSpell(message, id);
                    CheckSpell(message, id);
}
                }
else
                else
{
                {
llMessageLinked(LINK_THIS,98745920,message,id);
                    llMessageLinked(LINK_THIS,98745920,message,id);
}
                }
}
            }
}
        }
else
        else
{
        {
if (SpellChecker == 1)
            if (SpellChecker == 1)
{
            {
CheckSpell(message, id);
                CheckSpell(message, id);
}
            }
else
            else
{
            {
llMessageLinked(LINK_THIS,98745920,message,id);
                llMessageLinked(LINK_THIS,98745920,message,id);
}
            }
}
        }
DetectLanguage(message, id);
        DetectLanguage(message, id);
}
    }


http_response(key request_id, integer status, list metadata, string body)
    http_response(key request_id, integer status, list metadata, string body)
{  // Process Response Code
    {  // Process Response Code
if (~llListFindList(spellchecks, (list)request_id))
        if (~llListFindList(spellchecks, (list)request_id))
{
        {
integer splliPos = llListFindList(spellchecks, (list)request_id);
            string httmsg;
if(contains(body, "lt>") != 0)
            key httkey;
{  // Yahoo Spell Checker correction
            integer splliPos = llListFindList(spellchecks, (list)request_id);
llMessageLinked(LINK_THIS, 98745920,llGetSubString(body, llSubStringIndex(body, "t>") + 2, llSubStringIndex(body, "</") - 1),llList2Key(spellchecks, splliPos + 1));
            httkey = llList2Key(spellchecks, splliPos + 1);
llOwnerSay(llGetSubString(body, llSubStringIndex(body, "t>") + 2, llSubStringIndex(body, "</") - 1));
            if(contains(body, "<Result>") == 0)
spellchecks = llDeleteSubList(spellchecks,splliPos, splliPos + 3);
            {  // Yahoo Spell Checker correction
}
                httmsg = llList2String(spellchecks, splliPos + 2);
else
                llMessageLinked(LINK_THIS,98745920,strReplace(httmsg,"^ñ^",","),httkey);
{
            }
llMessageLinked(LINK_THIS,98745920,llList2String(spellchecks, splliPos + 2),llList2Key(spellchecks, splliPos + 1));
            else
spellchecks = llDeleteSubList(spellchecks,splliPos, splliPos + 3);
            {
}
                httmsg = llGetSubString(body, llSubStringIndex(body, "<Result>") + 8, llSubStringIndex(body, "</Result>") - 1);
}
                llMessageLinked(LINK_THIS, 98745920,httmsg,httkey);                              
if (~llListFindList(tempDetections, (list)request_id))
            }
{  // Language Detection
            spellchecks = llDeleteSubList(spellchecks,splliPos, splliPos + 3);
integer tmpliPos = llListFindList(tempDetections, (list)request_id);
        }
key speakerID = llList2Key(tempDetections, tmpliPos + 1);
        if (~llListFindList(tempDetections, (list)request_id))
tempDetections = llDeleteSubList(tempDetections, tmpliPos, tmpliPos + 2);
        {  // Language Detection
string htttmpStr = llToLower(llGetSubString(body, llSubStringIndex(body, "{\"language\":\"") + 13, llSubStringIndex(body, "\",\"isReliable\":") - 1));
            integer tmpliPos = llListFindList(tempDetections, (list)request_id);
if (contains(htttmpStr, "err") == 0 && contains(htttmpStr, "unn") == 0)
            key speakerID = llList2Key(tempDetections, tmpliPos + 1);
{  // We Trust the Google system, the Google´s guys are good and I am sure they will keep improving :-)
            tempDetections = llDeleteSubList(tempDetections, tmpliPos, tmpliPos + 2);
// Language Detected
            string htttmpStr = llToLower(llGetSubString(body, llSubStringIndex(body, "{\"language\":\"") + 13, llSubStringIndex(body, "\",\"isReliable\":") - 1));
llMessageLinked(LINK_THIS,6349160,htttmpStr,speakerID);
            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 :-)
}
                // Language Detected
}
                if(llStringLength(htttmpStr) <= 2)
                {
                    llMessageLinked(LINK_THIS,6349160,htttmpStr,speakerID);
                }
            }
        }
    }


timer()
    timer()
{
    {
llSetTimerEvent(0.0);
        llSetTimerEvent(0.0);
integer r;
        integer r;
list newList;
        list newList;
float timeElapsed;
        float timeElapsed;
for (r = 0; r < llGetListLength(spellchecks); r += 4)
        for (r = 0; r < llGetListLength(spellchecks); r += 4)
{
        {
timeElapsed = llGetTime() - llList2Float(spellchecks, r + 3);
            timeElapsed = llGetTime() - llList2Float(spellchecks, r + 3);
if (timeElapsed < 10.0)
            if (timeElapsed < 10.0)
{
            {
newList = (newList=[]) + newList + llList2List(spellchecks, r, r + 3);
                newList = (newList=[]) + newList + llList2List(spellchecks, r, r + 3);
}
            }
}
        }
spellchecks = newList;
        spellchecks = newList;
newList = [];
        newList = [];
for (r = 0; r < llGetListLength(tempDetections); r += 3)
        for (r = 0; r < llGetListLength(tempDetections); r += 3)
{
        {
timeElapsed = llGetTime() - llList2Float(tempDetections, r + 2);
            timeElapsed = llGetTime() - llList2Float(tempDetections, r + 2);
if (timeElapsed < 10.0)
            if (timeElapsed < 10.0)
{
            {
newList = (newList=[]) + newList + llList2List(tempDetections, r, r + 2);
                newList = (newList=[]) + newList + llList2List(tempDetections, r, r + 2);
}
            }
}
        }
tempDetections = newList;
        tempDetections = newList;
newList = [];
        newList = [];
llSetTimerEvent(5.0);
        llSetTimerEvent(5.0);
}
    }
}
}


Line 554: Line 505:
string SEPARATOR = "|%&|"; // for transmitting lists via linked messages
string SEPARATOR = "|%&|"; // for transmitting lists via linked messages
list translationCache;
list translationCache;
integer M = 1;
integer ShowTranslations = TRUE;
sendIM(key imid, string imstr)
{
    // llInstantMessage(key id , string message) causes the script to sleep for 2 seconds
    if (llGetAgentSize(imid) == ZERO_VECTOR)
    { }
    else
    {
        if (imid != llGetOwner())
        {
            llOwnerSay(imstr + " @" + llKey2Name(imid));  // llOwnerSay(string message) has no delay
        }
        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)
{ // converts a separated string created with List2TypeSep back to a list with the correct type information
    integer    i;
    list        input;
    list        output;
   
    input = llParseString2List(inputstring, [SEPARATOR], []);
    for (i = 0; i < llGetListLength(input); i += 2) {
        if (llList2Integer(input, i) == TYPE_INTEGER) output += (integer)llList2String(input, i + 1);
        else if (llList2Integer(input, i) == TYPE_FLOAT) output += (float)llList2String(input, i + 1);
        else if (llList2Integer(input, i) == TYPE_STRING) output += llList2String(input, i + 1);
        else if (llList2Integer(input, i) == TYPE_KEY) output += (key)llList2String(input, i + 1);
    }
   
    return output;
}


list String2List(string inputstring)
string List2TypeSep(list input) { // converts a list to a separated string with type information prepended to each item
{   // converts a separated string created with List2String back to a list
    integer    i;
list output;
    list       output;
output = llParseString2List(inputstring, [SEPARATOR], []);
 
return output;
    for (i = 0; i < llGetListLength(input); i++) {
        output += [llGetListEntryType(input, i)] + llList2List(input, i, i);
    }
   
    return llDumpList2String(output, SEPARATOR);
}
}
string List2String(list input)
 
{   // converts a list to a string
string strReplace(string str, string search, string replace) {
return llDumpList2String(input, SEPARATOR);
    return llDumpList2String(llParseStringKeepNulls((str = "") + str, [search], []), replace);
}
}


default
default
{
{
state_entry()
    state_entry()
{
    {
llSetTimerEvent(1.0);
        llSetTimerEvent(1.0);
}
    }
link_message(integer sender_num, integer num, string lstr, key id)
    link_message(integer sender_num, integer num, string lstr, key id)
{
    {
if (num == 7659759)
        if (num == 7659759)
        {
            agentsInTranslation = TypeSep2List(lstr);
            llOwnerSay("AgentsinTranslation List: \n" + llList2CSV(agentsInTranslation));
        }
        if (num == 9827491)
{
{
agentsInTranslation = String2List(lstr);
llSetTimerEvent(0.0);
            list txli;
            key recepientID;
            key txID;
            integer rxID;
            string recepientLanguage;
            string speakerLanguage;
            string txmessage;
            txID = id;
            txli = TypeSep2List(lstr);
            rxID = llList2Integer(txli,0);
            speakerLanguage = llList2String(txli,1);
            txmessage = llList2String(txli,2);
            recepientLanguage = llList2String(agentsInTranslation, llListFindList(agentsInTranslation, (list)txID) + 1);
            recepientID = getAgentKey(rxID);
            if (recepientID != NULL_KEY)
            {
                if (recepientLanguage == speakerLanguage)
                { }
                else
                {
                    sendIM(txID,txmessage);
                }
}
}
if (num == 98745920)
llSetTimerEvent(6.0);
 
        }
        if (num == 98745920)
{
{
integer w;
llSetTimerEvent(0.0);
string  spkrLan;
            integer w;
string  recepLan;
            string  spkrLan;
integer recepID;
            string  recepLan;
integer lstliPos;
            integer recepID;
string  lanpair;
            integer lstliPos;
//===============================
            string  lanpair;
// Formulate Translation Requests
            string txtchat;
//===============================
            key txID;
for (w = 0; w < llGetListLength(agentsInTranslation); w += 5)
float cacheTime;
{    // Loop through translation group and do appropriate translations as needed
list forli;
recepID = llList2Integer(agentsInTranslation, w + 4);
            txID = id;
recepLan = llList2String(agentsInTranslation, w + 1);
            txtchat = strReplace(lstr,",","^ñ^");
if (spkrLan == recepLan)
            llOwnerSay("Recibido mensaje de " + llKey2Name(id) + ", Mensaje: " + lstr);
{ }
            if (~llListFindList(agentsInTranslation, (list)txID))
else
            {
{
                spkrLan = llList2String(agentsInTranslation, llListFindList(agentsInTranslation, (list)txID ) + 1 );
lanpair = spkrLan + "|" + recepLan;
                llOwnerSay("Formulator script line 170 speakerLanguage: " + spkrLan);
if (~llListFindList(translationCache, (list)lanpair))
                cacheTime = llGetTime();
{
                //===============================
lstliPos = llListFindList(translationCache, (list)lanpair);
                // Formulate Translation Requests
translationCache = llListReplaceList(translationCache, [llList2String(translationCache, lstliPos + 1) + "@" + (string)recepID], lstliPos + 1, lstliPos + 1);
                //===============================
}
                for (w = 0; w < llGetListLength(agentsInTranslation); w += 5)
else
                {    // Loop through translation group and do appropriate translations as needed
{
                    recepID = llList2Integer(agentsInTranslation, w + 4);
translationCache = (translationCache=[]) + translationCache + [lanpair, recepID, llGetTime()];
                    recepLan = llList2String(agentsInTranslation, w + 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
                    for (w = 0; w < llGetListLength(translationCache); w += 3)
                    {  //====================================
                        //Translation
                        //====================================
//Forumulate and Send Translation Request
forli = [ txtchat + "&langpair=" + lanpair, llList2String(translationCache, w + 1), llList2String(translationCache, w)];
                        lanpair = "|" + llList2String(llParseStringKeepNulls(llList2String(translationCache, w), ["|"],[]), 1);
                        llMessageLinked(LINK_THIS, 2346017, List2TypeSep( forli ), txID);
                    }
                }
}
}
if (translationCache != [])
llSetTimerEvent(6.0);
{    // Process Requests
        }  
for (w = 0; w < llGetListLength(translationCache); w += 3)
    }
{  //====================================
//Translation
//====================================
//Forumulate and Send Translation Request
lanpair = "|" + llList2String(llParseStringKeepNulls(llList2String(translationCache, w), ["|"],[]), 1);
llMessageLinked(LINK_THIS,2346017,List2String( [llEscapeURL(lstr) + "&langpair=" + llEscapeURL(lanpair), llList2String(translationCache, w + 1), llList2String(translationCache, w)] ),id);
}
}
}
}


timer()
    timer()
{
    {
llSetTimerEvent(0.0);
        llSetTimerEvent(0.0);
integer r;
        integer r;
float timeElapsed;
        float timeElapsed;
list newList;
        list newList;
for (r = 0; r < llGetListLength(translationCache); r += 3)
        for (r = 0; r < llGetListLength(translationCache); r += 3)
{
        {
timeElapsed = llGetTime() - llList2Float(translationCache, r + 2);
            timeElapsed = llGetTime() - llList2Float(translationCache, r + 2);
if (timeElapsed < 8.0)
            if (timeElapsed < 8.0)
{
            {
newList = (newList=[]) + newList + llList2List(translationCache, r, r + 2);
                newList = (newList=[]) + newList + llList2List(translationCache, r, r + 2);
}
            }
}
        }
translationCache = newList;
        translationCache = newList;
newList = [];
        newList = [];
llMessageLinked(LINK_THIS,9876754,"",NULL_KEY);
        llMessageLinked(LINK_THIS,9876754,"",NULL_KEY);
llSetTimerEvent(5.0);
        llSetTimerEvent(9.0);
}
    }
}
}
</lsl>
</lsl>
Line 661: Line 750:
list requestedTranslations;
list requestedTranslations;
string SEPARATOR = "|%&|"; // for transmitting lists via linked messages
string SEPARATOR = "|%&|"; // for transmitting lists via linked messages
string strReplace(string str, string search, string replace) {
    return llDumpList2String(llParseStringKeepNulls((str = "") + str, [search], []), replace);
}


Translate(string chkmsg, list chkli)
Translate(string chkmsg, list chkli)
{
{
     returnValue = llHTTPRequest("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" + chkmsg, [HTTP_METHOD, "GET", HTTP_MIMETYPE, "plain/text;charset=utf-8"], "");
    string txmsg;
    list txli;
    txmsg = strReplace(chkmsg,"^ñ^",",");
    llOwnerSay("Translate List: \n" + llList2CSV(chkli) + "\n");
     returnValue = llHTTPRequest("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" + llEscapeURL(txmsg), [HTTP_METHOD, "GET", HTTP_MIMETYPE, "plain/text;charset=utf-8"], "");
     if (returnValue != NULL_KEY)
     if (returnValue != NULL_KEY)
     {    // Translation
     {    // Translation
         requestedTranslations = (requestedTranslations=[]) + requestedTranslations + [returnValue, llList2CSV(chkli)];
         txli = (txli=[]) + txli + [returnValue];
        txli = (txli=[]) + txli + [chkli];
        requestedTranslations = (requestedTranslations=[]) + requestedTranslations + txli;
         llSleep(0.6);
         llSleep(0.6);
     }
     }
Line 678: Line 777:
processHTTPResponse(string bodyStr, list httli)
processHTTPResponse(string bodyStr, list httli)
{
{
    llSetTimerEvent(0.0);
     key    recepientID;
     key    recepientID;
     key     speakerID;
     string     speakerID;
    list processli;
     list    paramtmpli;
     list    paramtmpli;
     list    recepientList;
     list    recepientList;
Line 692: Line 793:
     // Process Translation
     // Process Translation
     //===================
     //===================
     speakerID  = llList2Key(httli, 1);
    processli = httli;
     speakerName = llKey2Name(speakerID);
//    llOwnerSay("Process list: \n" + llList2CSV(processli) + "\n");
     speakerID  = llList2String(processli, 1);
     speakerName = llKey2Name((key)speakerID);
     if (speakerName == "")
     if (speakerName == "")
     {
     {
         speakerName = llList2String(llGetObjectDetails(speakerID, [OBJECT_NAME]), 0);
         speakerName = llList2String(llGetObjectDetails((key)speakerID, [OBJECT_NAME]), 0);
     }
     }
     recepientList = llParseString2List(llList2String(httli, 2), ["@"], []);
     recepientList = llParseString2List(llList2String(processli, 2), ["@"], []);
     paramtmpli = llParseStringKeepNulls(llList2String(httli, 3), ["|"],[]);
     paramtmpli = llParseStringKeepNulls(llList2String(processli, 3), ["|"],[]);
     recepientLanguage = llList2String(paramtmpli, 1);
     recepientLanguage = llList2String(paramtmpli, 1);
     languagePair = llDumpList2String(paramtmpli, ">>");
     languagePair = llDumpList2String(paramtmpli, ">>");
    llOwnerSay("Tanslator ProcessHttResponse\nFrom: " + speakerName + "\nTo: " + llList2CSV(recepientList) + "\nParams: " + llList2CSV(paramtmpli) + "\nRx Lan: " + recepientLanguage + "\nLanguage Pair: " + languagePair);
     // Perform Text Cleanup
     // Perform Text Cleanup
     translatedText = llGetSubString(bodyStr, llSubStringIndex(bodyStr, "{\"translatedText\":\"") + 18, llSubStringIndex(bodyStr, "\",\"detectedSourceLanguage\":\""));
     translatedText = llGetSubString(bodyStr, llSubStringIndex(bodyStr, "{\"translatedText\":\"") + 18, llSubStringIndex(bodyStr, "\",\"detectedSourceLanguage\":\""));
Line 717: Line 821:
     for (z = 0; z < llGetListLength(recepientList); z += 1)
     for (z = 0; z < llGetListLength(recepientList); z += 1)
     {
     {
            llMessageLinked(LINK_THIS,9827491, List2String( [ llList2Integer(recepientList, z), speakerLanguage , lantmpStr ] ) , recepientID);
        llMessageLinked(LINK_THIS,9827491, List2TypeSep( [ llList2Integer(recepientList, z), speakerLanguage , lantmpStr ] ) , recepientID);
     }
     }
    llSetTimerEvent(4.0);
     return;
     return;
}
}


string List2String(list input)
string List2TypeSep(list input) { // converts a list to a separated string with type information prepended to each item
{ // converts list to a string
    integer    i;
     return llDumpList2String(input, SEPARATOR);
    list        output;
 
    for (i = 0; i < llGetListLength(input); i++) {
        output += [llGetListEntryType(input, i)] + llList2List(input, i, i);
    }
   
     return llDumpList2String(output, SEPARATOR);
}
}


list String2List(string inputstring)
list TypeSep2List(string inputstring) { // converts a separated string created with List2TypeSep back to a list with the correct type information
{ // converts a separated string created with List2String back to a list
    integer    i;
     list output;
    list        input;
     output = llParseString2List(inputstring, [SEPARATOR], []);   
     list       output;
      
    input = llParseString2List(inputstring, [SEPARATOR], []);
 
    for (i = 0; i < llGetListLength(input); i += 2) {
        if (llList2Integer(input, i) == TYPE_INTEGER) output += (integer)llList2String(input, i + 1);
        else if (llList2Integer(input, i) == TYPE_FLOAT) output += (float)llList2String(input, i + 1);
        else if (llList2Integer(input, i) == TYPE_STRING) output += llList2String(input, i + 1);
        else if (llList2Integer(input, i) == TYPE_KEY) output += (key)llList2String(input, i + 1);
    }    
     return output;
     return output;
}
}
Line 743: Line 863:
     {
     {
         if (num == 2346017)
         if (num == 2346017)
         {
         {          
             list txli;
             list txli;
             key txID;
             key txID;
             txli = String2List(lstr);
             txli = TypeSep2List(lstr);
             txID = lid;
            llOwnerSay("Translator link_message list: " + llList2CSV(txli));
             txID = lid;          
             Translate(llList2String(txli,0),[ llGetTime(), txID, llList2String(txli,1), llList2String(txli,2) ] );
             Translate(llList2String(txli,0),[ llGetTime(), txID, llList2String(txli,1), llList2String(txli,2) ] );
         }
         }
Line 771: Line 892:
         float timeElapsed;
         float timeElapsed;
         list newList;
         list newList;
         for (r = 0; r < llGetListLength(requestedTranslations); r += 5)
         for (r = 0; r < llGetListLength(requestedTranslations); r += 6)
         {
         {
             timeElapsed = llGetTime() - llList2Float(requestedTranslations, r + 1);
             timeElapsed = llGetTime() - llList2Float(requestedTranslations, r + 1);
             if (timeElapsed < 20.0)
             if (timeElapsed < 20.0)
             {
             {
                 newList = (newList=[]) + newList + llList2List(requestedTranslations, r, r + 4);
                 newList = (newList=[]) + newList + llList2List(requestedTranslations, r, r + 5);
             }
             }
         }
         }

Revision as of 08:30, 30 December 2009

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 NOT TESTED

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 //Spell Checker Web Services powered by Yahoo key owner; list agentsInTranslation; integer isInitialized = FALSE; integer listenID; integer isMaster = 1; integer autoLanguage = TRUE; integer enabled = FALSE; string SEPARATOR = "|%&|"; // for transmitting lists via linked messages

string checkLanguage(string chklantmpStr) {

   if (chklantmpStr == "")
   {
       chklantmpStr = "en";
   }
   else if (chklantmpStr == "und")
   {
       chklantmpStr = "el";
   }
   if (llGetSubString(chklantmpStr, 0, 1) == "zh")
   {
       chklantmpStr = "zh-CN";
   }
   else
   {
       chklantmpStr = llGetSubString(chklantmpStr, 0, 1);
   }
   return chklantmpStr;

}

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 ];        // llMessageLinked(LINK_THIS, 64562349, avlan, avid);
   }

}

string addNewAgent(key newavid) {

   string speakerLan;
   if (llGetAgentSize(newavid) == ZERO_VECTOR)
   {
       speakerLan = "en";
       addAgent(newavid, speakerLan, 4);
   }
   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 input) { // converts a list to a separated string with type information prepended to each item

   integer     i;
   list        output;
   for (i = 0; i < llGetListLength(input); i++) {
       output += [llGetListEntryType(input, i)] + llList2List(input, i, i);
   }
   
   return llDumpList2String(output, SEPARATOR);

}

list TypeSep2List(string inputstring) { // converts a separated string created with List2TypeSep back to a list with the correct type information

   integer     i;
   list        input;
   list        output;
   
   input = llParseString2List(inputstring, [SEPARATOR], []);
   for (i = 0; i < llGetListLength(input); i += 2) {
       if (llList2Integer(input, i) == TYPE_INTEGER) output += (integer)llList2String(input, i + 1);
       else if (llList2Integer(input, i) == TYPE_FLOAT) output += (float)llList2String(input, i + 1);
       else if (llList2Integer(input, i) == TYPE_STRING) output += llList2String(input, i + 1);
       else if (llList2Integer(input, i) == TYPE_KEY) output += (key)llList2String(input, i + 1);
   }
   
   return output;

}

default {

   state_entry()
   {
       owner = llGetOwner();
       llSetTimerEvent(1.0);
   }
   link_message(integer sender_num, integer num, string lstr, key lid)
   {
       if (num == 9876754)
       {
           llMessageLinked(LINK_THIS,7659759,List2TypeSep(agentsInTranslation),NULL_KEY);
       }
       if (num == 6349160)
       {
           key speaker;
           string spkLan;
           speaker = lid;
           spkLan = lstr;
           if (~llListFindList(agentsInTranslation, (list)speaker))
           {
               integer tmpavliPos = llListFindList(agentsInTranslation, (list)speaker);
               string actlan = llList2String(agentsInTranslation, tmpavliPos + 1);
               string 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);
                   }
               }
           }
       }
   }
   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);
           }
       }
   }
   no_sensor()
   { }
   listen(integer channel, string name, key id, string message)
   {
       if(~llListFindList(agentsInTranslation, (list)id))
       { }
       else
       {
           addNewAgent(id);
       }
   }
   timer()
   {
       integer r;
       vector  tmrVct;
       list tmrli;
       list  newList;
       llSetTimerEvent(0.0);   // we better reset timer by way of precaution
       if (isInitialized == FALSE)
       {
           string mylanguage;
           enabled = TRUE;
           listenID = llListen(0, "", "", "");
           llMessageLinked(LINK_THIS, 6877259, (string)enabled, NULL_KEY);
           isInitialized = TRUE;
           mylanguage = llGetAgentLanguage(owner);
           if (llStringLength(mylanguage) < 1)
           {
               mylanguage = "en";
           }
           if(~llListFindList(agentsInTranslation, (list)owner))
           {
               integer ownerliPos;
               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];
           }
       }
       if (isMaster > 0)
       {
           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 = [];
       }
       if (autoLanguage == TRUE && isMaster > 0)
       {
           llSensor("", NULL_KEY, AGENT, 20.0, PI);
       }
       llSetTimerEvent(4.0);   // restart timer
   }

} </lsl>


CheckSpell-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 //Spell Checker Web Services powered by Yahoo key splValue; key dtcValue; integer autoLanguage = TRUE; integer isMaster = 1; integer enabled = TRUE; integer showTranslation = TRUE; integer tranObjects = TRUE; integer SpellChecker = 1; list tempDetections; list spellchecks;

string strReplace(string str, string search, string replace) {

   return llDumpList2String(llParseStringKeepNulls((str = "") + str, [search], []), replace);

}

integer contains(string haystack, string needle) // http://wiki.secondlife.com/wiki/llSubStringIndex {

   return ~llSubStringIndex(haystack, needle);

}

DetectLanguage(string dtcmsg, key dtcid) {

   llSleep(0.2);
   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
   }

}

CheckSpell(string splmsg, key splid) {

   splValue = llHTTPRequest("http://search.yahooapis.com/WebSearchService/V1/spellingSuggestion?appid=DNPjiabV34EOgXQ3kAu6.d7kf6v.JUGCn1bFUcSTFMSGCyCy_ALzbepYstlI7DrOGP0-&query=" + llEscapeURL(splmsg), [HTTP_METHOD, "GET", HTTP_MIMETYPE, "plain/text;charset=utf-8"], "");
   if (splValue != NULL_KEY)
   {    // Translation
       spellchecks = (spellchecks=[]) + spellchecks + [ splValue, splid, strReplace(splmsg,",","^ñ^"), llGetTime() ];
   }
   else
   {
       llSleep(10.0); // Something has gone horribly wrong, sleep 10 seconds clear throttle
   }

}


default {

   state_entry()
   {
       llListen(0,"","","");
   }
   listen(integer channel, string name, key id, string message)
   {
       if ((!enabled) && (isMaster == 1))
       {
           return;
       }
       if (!tranObjects)
       {
           if (llGetAgentSize(id) == ZERO_VECTOR)
           {
               return;
           }
           else
           {
               if (SpellChecker == 1)
               {
                   CheckSpell(message, id);
               }
               else
               {
                   llMessageLinked(LINK_THIS,98745920,message,id);
               }
           }
       }
       else
       {
           if (SpellChecker == 1)
           {
               CheckSpell(message, id);
           }
           else
           {
               llMessageLinked(LINK_THIS,98745920,message,id);
           }
       }
       DetectLanguage(message, id);
   }
   http_response(key request_id, integer status, list metadata, string body)
   {   // Process Response Code
       if (~llListFindList(spellchecks, (list)request_id))
       {
           string httmsg;
           key httkey;
           integer splliPos = llListFindList(spellchecks, (list)request_id);
           httkey = llList2Key(spellchecks, splliPos + 1);
           if(contains(body, "<Result>") == 0)
           {   // Yahoo Spell Checker correction
               httmsg = llList2String(spellchecks, splliPos + 2);
               llMessageLinked(LINK_THIS,98745920,strReplace(httmsg,"^ñ^",","),httkey);
           }
           else
           {
               httmsg = llGetSubString(body, llSubStringIndex(body, "<Result>") + 8, llSubStringIndex(body, "</Result>") - 1);
               llMessageLinked(LINK_THIS, 98745920,httmsg,httkey);                               
           }
           spellchecks = llDeleteSubList(spellchecks,splliPos, splliPos + 3);
       }
       if (~llListFindList(tempDetections, (list)request_id))
       {   // Language Detection
           integer tmpliPos = llListFindList(tempDetections, (list)request_id);
           key speakerID = llList2Key(tempDetections, tmpliPos + 1);
           tempDetections = llDeleteSubList(tempDetections, tmpliPos, tmpliPos + 2);
           string 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 :-)
               // Language Detected
               if(llStringLength(htttmpStr) <= 2)
               {
                   llMessageLinked(LINK_THIS,6349160,htttmpStr,speakerID);
               }
           }
       }
   }
   timer()
   {
       llSetTimerEvent(0.0);
       integer r;
       list newList;
       float timeElapsed;
       for (r = 0; r < llGetListLength(spellchecks); r += 4)
       {
           timeElapsed = llGetTime() - llList2Float(spellchecks, r + 3);
           if (timeElapsed < 10.0)
           {
               newList = (newList=[]) + newList + llList2List(spellchecks, r, r + 3);
           }
       }
       spellchecks = newList;
       newList = [];
       for (r = 0; r < llGetListLength(tempDetections); 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 //Spell Checker Web Services powered by Yahoo list agentsInTranslation; string SEPARATOR = "|%&|"; // for transmitting lists via linked messages list translationCache; integer M = 1; integer ShowTranslations = TRUE;

sendIM(key imid, string imstr) {

   // llInstantMessage(key id , string message) causes the script to sleep for 2 seconds
   if (llGetAgentSize(imid) == ZERO_VECTOR)
   { }
   else
   {
       if (imid != llGetOwner())
       {
           llOwnerSay(imstr + " @" + llKey2Name(imid));  // llOwnerSay(string message) has no delay
       }
       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) { // converts a separated string created with List2TypeSep back to a list with the correct type information

   integer     i;
   list        input;
   list        output;
   
   input = llParseString2List(inputstring, [SEPARATOR], []);
   for (i = 0; i < llGetListLength(input); i += 2) {
       if (llList2Integer(input, i) == TYPE_INTEGER) output += (integer)llList2String(input, i + 1);
       else if (llList2Integer(input, i) == TYPE_FLOAT) output += (float)llList2String(input, i + 1);
       else if (llList2Integer(input, i) == TYPE_STRING) output += llList2String(input, i + 1);
       else if (llList2Integer(input, i) == TYPE_KEY) output += (key)llList2String(input, i + 1);
   }
   
   return output;

}

string List2TypeSep(list input) { // converts a list to a separated string with type information prepended to each item

   integer     i;
   list        output;
   for (i = 0; i < llGetListLength(input); i++) {
       output += [llGetListEntryType(input, i)] + llList2List(input, i, i);
   }
   
   return llDumpList2String(output, SEPARATOR);

}

string strReplace(string str, string search, string replace) {

   return llDumpList2String(llParseStringKeepNulls((str = "") + str, [search], []), replace);

}

default {

   state_entry()
   {
       llSetTimerEvent(1.0);
   }
   link_message(integer sender_num, integer num, string lstr, key id)
   {
       if (num == 7659759)
       {
           agentsInTranslation = TypeSep2List(lstr);
           llOwnerSay("AgentsinTranslation List: \n" + llList2CSV(agentsInTranslation));
       }
       if (num == 9827491)

{ llSetTimerEvent(0.0);

           list txli;
           key recepientID;
           key txID;
           integer rxID;
           string recepientLanguage;
           string speakerLanguage;
           string txmessage;
           txID = id;
           txli = TypeSep2List(lstr);
           rxID = llList2Integer(txli,0);
           speakerLanguage = llList2String(txli,1);
           txmessage = llList2String(txli,2);
           recepientLanguage = llList2String(agentsInTranslation, llListFindList(agentsInTranslation, (list)txID) + 1);
           recepientID = getAgentKey(rxID);
           if (recepientID != NULL_KEY)
           {
               if (recepientLanguage == speakerLanguage)
               { }
               else
               {
                   sendIM(txID,txmessage);
               }

} llSetTimerEvent(6.0);

       }
       if (num == 98745920)

{ llSetTimerEvent(0.0);

           integer w;
           string  spkrLan;
           string  recepLan;
           integer recepID;
           integer lstliPos;
           string  lanpair;
           string txtchat;
           key txID;

float cacheTime; list forli;

           txID = id;
           txtchat = strReplace(lstr,",","^ñ^");
           llOwnerSay("Recibido mensaje de " + llKey2Name(id) + ", Mensaje: " + lstr);
           if (~llListFindList(agentsInTranslation, (list)txID))
           {
               spkrLan = llList2String(agentsInTranslation, llListFindList(agentsInTranslation, (list)txID ) + 1 );
               llOwnerSay("Formulator script line 170 speakerLanguage: " + spkrLan);
               cacheTime = llGetTime();
               //===============================
               // Formulate Translation Requests
               //===============================
               for (w = 0; w < llGetListLength(agentsInTranslation); w += 5)
               {    // Loop through translation group and do appropriate translations as needed
                   recepID = llList2Integer(agentsInTranslation, w + 4);
                   recepLan = llList2String(agentsInTranslation, w + 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
                   for (w = 0; w < llGetListLength(translationCache); w += 3)
                   {   //====================================
                       //Translation
                       //====================================

//Forumulate and Send Translation Request forli = [ txtchat + "&langpair=" + lanpair, llList2String(translationCache, w + 1), llList2String(translationCache, w)];

                       lanpair = "|" + llList2String(llParseStringKeepNulls(llList2String(translationCache, w), ["|"],[]), 1);
                       llMessageLinked(LINK_THIS, 2346017, List2TypeSep( forli ), txID);
                   }
               }

} llSetTimerEvent(6.0);

       } 
   }
   timer()
   {
       llSetTimerEvent(0.0);
       integer r;
       float timeElapsed;
       list newList;
       for (r = 0; r < llGetListLength(translationCache); r += 3)
       {
           timeElapsed = llGetTime() - llList2Float(translationCache, r + 2);
           if (timeElapsed < 8.0)
           {
               newList = (newList=[]) + newList + llList2List(translationCache, r, r + 2);
           }
       }
       translationCache = newList;
       newList = [];
       llMessageLinked(LINK_THIS,9876754,"",NULL_KEY);
       llSetTimerEvent(9.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 //Spell Checker Web Services powered by Yahoo integer tranObjects = TRUE; integer SpellChecker = TRUE; integer isMaster = 1; integer enabled = FALSE; key returnValue; list requestedTranslations; string SEPARATOR = "|%&|"; // for transmitting lists via linked messages

string strReplace(string str, string search, string replace) {

   return llDumpList2String(llParseStringKeepNulls((str = "") + str, [search], []), replace);

}

Translate(string chkmsg, list chkli) {

   string txmsg;
   list txli;
   txmsg = strReplace(chkmsg,"^ñ^",",");
   llOwnerSay("Translate List: \n" + llList2CSV(chkli) + "\n");
   returnValue = llHTTPRequest("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" + llEscapeURL(txmsg), [HTTP_METHOD, "GET", HTTP_MIMETYPE, "plain/text;charset=utf-8"], "");
   if (returnValue != NULL_KEY)
   {    // Translation
       txli = (txli=[]) + txli + [returnValue];
       txli = (txli=[]) + txli + [chkli];
       requestedTranslations = (requestedTranslations=[]) + requestedTranslations + txli;
       llSleep(0.6);
   }
   else
   {
       llSleep(25.0); // Something has gone horribly wrong, sleep 25 seconds to clear throttle
   }

}

processHTTPResponse(string bodyStr, list httli) {

   llSetTimerEvent(0.0);
   key     recepientID;
   string     speakerID;
   list processli;
   list    paramtmpli;
   list    recepientList;
   string  recepientLanguage;
   string  languagePair;
   string  speakerName;
   string  speakerLanguage;
   string  translatedText;
   string  lantmpStr;
   integer z;
   //===================
   // Process Translation
   //===================
   processli = httli;

// llOwnerSay("Process list: \n" + llList2CSV(processli) + "\n");

   speakerID  = llList2String(processli, 1);
   speakerName = llKey2Name((key)speakerID);
   if (speakerName == "")
   {
       speakerName = llList2String(llGetObjectDetails((key)speakerID, [OBJECT_NAME]), 0);
   }
   recepientList = llParseString2List(llList2String(processli, 2), ["@"], []);
   paramtmpli = llParseStringKeepNulls(llList2String(processli, 3), ["|"],[]);
   recepientLanguage = llList2String(paramtmpli, 1);
   languagePair = llDumpList2String(paramtmpli, ">>");
   llOwnerSay("Tanslator ProcessHttResponse\nFrom: " + speakerName + "\nTo: " + llList2CSV(recepientList) + "\nParams: " + llList2CSV(paramtmpli) + "\nRx Lan: " + recepientLanguage + "\nLanguage Pair: " + languagePair);
   // Perform Text Cleanup
   translatedText = llGetSubString(bodyStr, llSubStringIndex(bodyStr, "{\"translatedText\":\"") + 18, llSubStringIndex(bodyStr, "\",\"detectedSourceLanguage\":\""));
   // Reverse order if Recepient Language is Hebrew or Arabic
   if ((recepientLanguage == "iw") || (recepientLanguage == "ar"))
   {
       lantmpStr = "";
       for(z = llStringLength(translatedText);z >= 0; z--)
       {
           lantmpStr = (lantmpStr="") + lantmpStr + llGetSubString(translatedText, z, z);
       }
       translatedText = lantmpStr;
   }
   lantmpStr = speakerName + "(" + languagePair + "): " + translatedText;
   for (z = 0; z < llGetListLength(recepientList); z += 1)
   {
       llMessageLinked(LINK_THIS,9827491, List2TypeSep( [ llList2Integer(recepientList, z), speakerLanguage , lantmpStr ] ) , recepientID);
   }
   llSetTimerEvent(4.0);
   return;

}

string List2TypeSep(list input) { // converts a list to a separated string with type information prepended to each item

   integer     i;
   list        output;
   for (i = 0; i < llGetListLength(input); i++) {
       output += [llGetListEntryType(input, i)] + llList2List(input, i, i);
   }
   
   return llDumpList2String(output, SEPARATOR);

}

list TypeSep2List(string inputstring) { // converts a separated string created with List2TypeSep back to a list with the correct type information

   integer     i;
   list        input;
   list        output;
   
   input = llParseString2List(inputstring, [SEPARATOR], []);
   for (i = 0; i < llGetListLength(input); i += 2) {
       if (llList2Integer(input, i) == TYPE_INTEGER) output += (integer)llList2String(input, i + 1);
       else if (llList2Integer(input, i) == TYPE_FLOAT) output += (float)llList2String(input, i + 1);
       else if (llList2Integer(input, i) == TYPE_STRING) output += llList2String(input, i + 1);
       else if (llList2Integer(input, i) == TYPE_KEY) output += (key)llList2String(input, i + 1);
   }   
   return output;

}

default {

   state_entry()
   {
       llSetTimerEvent(1.0);
   }
   link_message(integer sender_num, integer num, string lstr, key lid)
   {
       if (num == 2346017)
       {            
           list txli;
           key txID;
           txli = TypeSep2List(lstr);
           llOwnerSay("Translator link_message list: " + llList2CSV(txli));
           txID = lid;            
           Translate(llList2String(txli,0),[ llGetTime(), txID, llList2String(txli,1), llList2String(txli,2) ] );
       }
   }
   http_response(key request_id, integer status, list metadata, string body)
   {   // Process Response Code
       if (~llListFindList(requestedTranslations, (list)request_id))
       {   // Translation
           integer httliPos;
           string httmsg;
           httliPos = llListFindList(requestedTranslations, (list)request_id);
           httmsg = body;
           processHTTPResponse(httmsg, llList2List(requestedTranslations, httliPos + 1, httliPos + 4 ));
           requestedTranslations = llDeleteSubList(requestedTranslations, httliPos, httliPos + 4);
           return;
       }
   }
   timer()
   {
       llSetTimerEvent(0.0);
       integer r;
       float timeElapsed;
       list newList;
       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 Example <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 //Spell Checker Web Services powered by Yahoo

string strReplace(string str, string search, string replace) {

   return llDumpList2String(llParseStringKeepNulls((str = "") + str, [search], []), replace);

}

sendim(string mess, key target) {

   if (llGetAgentSize(target) == ZERO_VECTOR)
   { }
   else
   {
       llInstantMessage(target, llUnescapeURL(mess));
   }

}


default {

   state_entry()
   {
   }
   link_message(integer sender_num, integer num, string str, key id)
   {
       if (num == 2334400)
       {
           sendim(strReplace(str,"\\u0026#39;","´"),id);
       }
   }

}

</lsl>