When you are flying around in Second Life you have certainly noticed that there are no support for multi-language, meaning everything is in English and there is no option to change it. The following tutorial will explain how by using textures and the Linden Scripting Language it is possible to make a multi-language support for your world including an adaptive language change for dialog boxes.

As you may already know it’s not possible to store data in a persistent way in SL. It means that if you cannot create a variable that would be accessible between objects. This is very annoying because if we want to use a common variable for two, three or n objects we will need to implement say/listen states that would send the variable value to all these objects. This is not very practical if you want to have what we’ll call a global variable.

So we need to find a way to store a permanent variable: we will use a simple webserver and a database to achieve this. Thanks to this tutorial you will even be able to solve the problem of regionalization in dialog boxes.

Step 1: What do you need ?
  • A Second Life client
  • A webserver with PHP support (Apache Server) + MySQL database
Step 2: Setting up the PHP file
In order to store the selected language for each avatar, we need to store this value somewhere. The best way to do this, since Second Life doesn’t completely permit to setup a cookie is to create a little PHP script that is going to take the value of two variables ( idAvatar and lang) passed in an URL. We are going to write this PHP script in a file called slLang.php

Since we want something very easy and not two classes we are going to fit this “two-way” script in only file. In the first if-case we are going to store the idAvatar and the lang in the database (http://yourserver.com/slLang.php?idAvatar=1234-1234-1234-1234&lang=FR)

In the second if-case there is only the variable idAvatar that is passed in the URL. As a result of calling your script (http://yourserver.com/slLang.php?idAvatar=1234-1234-1234-1234) you will get back a small string with the value of the language. In our case we would get ‘FR’.

Now you actually only need to copy and paste the code snippet in a file called slLang.php and to setup a file called config.inc.php with the connection settings to your database (generally provided by your web host).


/* Class to handle the language for each avatar */

$idAvatar =  $HTTP_GET_VARS["idAvatar"];
$lang = $HTTP_GET_VARS["lang"];

/* Puts, updates the lang in the table */
if(isset($idAvatar ) && isset($lang))
 $myQuery = "SELECT COUNT(*) FROM language WHERE idAvatar= '".$idAvatar."'";
 $result = mysql_db_query("slmining",$myQuery) or die('Error searching the avatar');
 $avatarCount = mysql_result($result,0);

 if($avatarCount == 1)
    $myQuery ="UPDATE language SET lang =  '".$lang."' WHERE idAvatar = '".$idAvatar."'"  ;

 if($avatarCount == 0)
    $myQuery ="INSERT INTO  language VALUES ('".$idAvatar."','".$lang."')";
    mysql_db_query("slmining",$myQuery) or die('Error adding avatar to database');

/* Returns the lang value stored in the table */
if(isset($idAvatar ) && !isset($lang)){

    $myQuery = "SELECT lang FROM language WHERE idAvatar= '".$idAvatar."'";
    $result = mysql_db_query("slmining",$myQuery) or die('Error getting the language for  this avatar');
    $avatarLanguage = mysql_result($result,0);

// This outputs the language value. It will be then analyzed by the LSL Script
echo $avatarLanguage;  

Step 3: Writing the Linden Scripting Language

Now we need to implement the objects on the Second Life side. For this create two objects and apply a texture (e.g. a flag) on this object. You could also a apply a texture with instructions in several languages and with small balls let the avatar choose the correct language.

Then select “Content” and “Create new script”. The code to put in the box is very simple: we are only posting the language corresponding to the avatar’s choice.

Language choosing boxes
We are going to save the language value for the avatar who pressed on the box in the database. The id of the avatar is given by the function (string) llDetectedKey(0). Once touched the box sends over the function llHTTPRequest() the avatar’s id and the selected language. This is very interesting when you have hundreds of avatars with tens of languages: using a list or a listen state would mean a high memory usage that can lead to script problems.
key requestid;


touch_start(integer total_number)
// Change your language e.g. &lang=EN or &lang=DE
string url = "http://yourserver.com/slLang.php?idAvatar="+(string)llDetectedKey(0)+"&lang=DE";

requestid = llHTTPRequest(url,[HTTP_METHOD,"POST"],"");

One interesting feature of using the database trick, is that every avatar has his own language all over your island or building. For instance an avatar can select “French” a second one “German” and a third one “English” and all the dialog boxes will show a message in the language
list MENU = ["OK"];
string MESSAGE_GERMAN = "Eine Nachricht auf Deutsch";
string MESSAGE_ENGLISH = "A message in English";
string MESSAGE_FRENCH = "Un message en francais";

string messageToShow="";
key requestid;
key currentAvatarId;


touch_start(integer total_number)
// We are asking which language we have to display
currentAvatarId = llDetectedKey(0);
string url = "http://yourserver.com/slLang.php?idAvatar="+(string)llDetectedKey(0);
requestid = llHTTPRequest(url,[HTTP_METHOD,"POST"],"");


// After having requested we need to know which language was stored
// Very practical, because each avatar will have his own language
http_response(key request_id, integer status, list metadata, string body){

if(request_id == requestid)
messageToShow  = MESSAGE_GERMAN
messageToShow  = MESSAGE_ENGLISH;
messageToShow  = MESSAGE_FRENCH;

// ... you can add as many language as you want
Listening objects (e.g. textures)
You can easily extend this exemple by changing a texture with the setTexture() function.
Step 4: Extensions
Knowing the language of your visitor might me very useful. The interaction with the database could also help you to store other temporary information such as their names, their positions etc… For instance you can check how many people are speaking one language and then provide specific data. For e-classes this can be very interesting: the professor will know which language the majority of his student will understand. Of course we can extend this tutorial to build a database driven poll with the possibility to generate a real-time result chart by modifying textures and the properties of objects.