====== How to Use Auto Translation on Script ======
In This Tutorial there is special new API to detect player language.
local result,languageCode,areaCountry = Player:GetLanguageAndRegion(playerid);
If your Account created in Indonesia and using English language on current Session. It will output this
result = 0
languageCode = "en"
areaCountry = "ID"
Let's Jump Straight into the Tutorial
===== Tutorial Auto Translation on Script =====
==== Step 1 ====
The file of this script must be on top of script you are going to use translation.
{{:developer_center:developer_editor:script:translationscriptfile.png?800|}}
Copy and Paste this Script Bellow into "Language Session of Player"
playerSession = {}
ScriptSupportEvent:registerEvent("Game.AnyPlayer.EnterGame",function(e)
local playerid = e.eventobjid;
local r,lc,ar = Player:GetLanguageAndRegion(playerid);
if(r==0)then
playerSession[playerid]={lc=lc,ar=ar};
else
playerSession[playerid]={lc="en",ar="EN"};
end
end)
lang = {Chinese="cn",English="en",Taiwan="tw",Thailand= "tha",Espanyol="esn",Portuguese="ptb",French="fra",Japan="jpn",Arabic="ara",Korea="kor",Vietnam="vie",Russia="rus",Turkey="tur",Italia="ita",German="ger",Indonesia="ind",Malaysia = "msa"};
T_Text = {};
function toIndex(nonIndex)
return string.gsub(nonIndex," ","_");
end
function getSession(playerid)
return playerSession[playerid].lc
end
T_Text_meta = {
__index = function(table,key)
T_Text[key]={};
return T_Text[key];
end,
__add = function(a, b)
a[toIndex(b[3])][b[1]] = b[2]
return a[toIndex(b[3])][b[1]];
end,
__sub = function(a,b)
a[toIndex(b[2])][b[1]] = nil;
end,
__call = function(t,playerid,key)
return t[toIndex(key)][toIndex(getSession(playerid))]
end
}
T_Text = setmetatable(T_Text,T_Text_meta);
function createText(langcode,keystring,value) return T_Text + {langcode,value,keystring}; end