Hi. Now I will tell you how to do a simple localization for the server without the use of too large code.
First create an array or table with the desired languages. I have this RU, PL and EN.
Then add in the table new item - the same table, but now with two fields - text and x. Text is a string and x is a number. Yet will leave them empty.
The text field is directly is our translation, and the x - offset the x coordinate. The same words in different languages can occupy different space, so we need to have everything in its place. For example, take the word "Hi".
We see that the English word "Hi" is shorter than Russian or Polish, so we do the offset. I don't have exact coordinates, so we imagine that we enter our text in the button, and make the shift to the left.
Now that we have the translation, add it to our array.
Now that we have the translation, let's send it to a file with our GUI.
Now make a function to calculate the current language of the user, which is installed in the launcher.
Now that we have the translation, information about the language and the offset - you can add it in our texts.
That's about it. If you have any comments, questions, or suggestions, write them here, please. Also ready to answer all GG: 60474243
An example of the translation:
![[Image: ZHHTaxx.jpg]](http://i.imgur.com/ZHHTaxx.jpg)
First create an array or table with the desired languages. I have this RU, PL and EN.
Code:
local translation = [];
local en = {};
local ru = {};
local pl = {};
Then add in the table new item - the same table, but now with two fields - text and x. Text is a string and x is a number. Yet will leave them empty.
Code:
local translation = [];
local en = {
hello = {text = "", x = 0}
};
local ru = {
hello = {text = "", x = 0}
};
local pl = {
hello = {text = "", x = 0}
};
The text field is directly is our translation, and the x - offset the x coordinate. The same words in different languages can occupy different space, so we need to have everything in its place. For example, take the word "Hi".
Code:
local translation = [];
local en = {
hello = {text = "Hi", x = 0}
};
local ru = {
hello = {text = "Привет", x = 0}
};
local pl = {
hello = {text = "Witam", x = 0}
};
We see that the English word "Hi" is shorter than Russian or Polish, so we do the offset. I don't have exact coordinates, so we imagine that we enter our text in the button, and make the shift to the left.
Code:
local translation = [];
local en = {
hello = {text = "Hi", x = 0} //Without offset
};
local pl = {
hello = {text = "Привет", x = -60} //Offset to the left on 60
};
local pl = {
hello = {text = "Witam", x = -50} //Offset to the left on 50
};
Now that we have the translation, add it to our array.
Code:
local translation = [];
local en = {
hello = {text = "Hi", x = 0}
};
local ru = {
hello = {text = "Привет", x = -60}
};
local pl = {
hello = {text = "Witam", x = -50}
};
translation.append(en); // index = 0
translation.append(ru); // index = 1
translation.append(pl); // index = 2
function getTranslation() // function for send our translation to other files
{
return translation;
}
Now that we have the translation, let's send it to a file with our GUI.
Code:
local translation = getTranslation();
Now make a function to calculate the current language of the user, which is installed in the launcher.
Code:
local translation = getTranslation();
local lang = -1; // language variable
function checkLanguage()
{
local lg = getLanguage();
if (lg == "ru")
{
lang = 1;
}
else if (lg == "pl")
{
lang = 2;
}
else
{
lang = 0;
}
}
addEvent("onInit",function() // check language on start game
{
checkLanguage();
});
Now that we have the translation, information about the language and the offset - you can add it in our texts.
Code:
local translation = getTranslation();
local lang = -1; // language variable
function checkLanguage()
{
local lg = getLanguage();
if (lg == "ru")
{
lang = 1;
}
else if (lg == "pl")
{
lang = 2;
}
else
{
lang = 0;
}
}
addEvent("onInit",function() // check language on start game
{
checkLanguage();
});
local hello_draw = createDraw(translation[lang].hello.text,"Font_Old_10_White_Hi.TGA",1000 + translation[lang].hello.x,1000,255,255,255,true);
// depending on the language will be chosen one or another table with the translation
addEvent("onRespawn",function() //show draw
{
setDrawVisible(hello_draw,true);
});
That's about it. If you have any comments, questions, or suggestions, write them here, please. Also ready to answer all GG: 60474243
An example of the translation:
![[Image: ZHHTaxx.jpg]](http://i.imgur.com/ZHHTaxx.jpg)
![[Image: AaEWBGo.png]](http://i.imgur.com/AaEWBGo.png)