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
-- Local Hosted Server result = 0 languageCode = "en" areaCountry = "ID" -- Cloud Server result = 0 languageCode = 1 areaCountry = nil
Let's Jump Straight into the Tutorial
We will be Installing the following framework just in 2 step
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); local codeLang = {"en", "cn", "tw", "tha", "esn", "ptb", "fra", "jpn", "ara", "kor", "vie", "rus", "tur", "ita", "ger", "ind", "msa"}; if(r==0)then local inlangcode = tonumber(lc); if(inlangcode and inlangcode>=0)then playerSession[playerid]={lc=codeLang[lc+1],ar=""} or {lc="cn",ar=""} else playerSession[playerid]={lc=lc,ar=ar}; end else playerSession[playerid]={lc="en",ar="EN"}; end end) 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_Text,playerid,key) if T_Text[toIndex(key)][getSession(playerid)] == nil then --Chat:sendSystemMsg("#RERROR T_Text "..toIndex(key).." is Not Defined!",1029380338); --print("Session from [",playerid,"] got an Error",getSession(playerid)); --print("What is T ?",T_Text); return key end return T_Text[toIndex(key)][getSession(playerid)] end } T_Text = setmetatable(T_Text,T_Text_meta); function createText(langcode,value,keystring) return T_Text + {langcode,value,keystring}; end
-- let's assume Player is from Spain -- Cannot Directly be Used before player joined the game T_Text(playerid,"Hello World") --> "Hola Mundo"
We are going to use Spreadsheet from Google to define the string translation. So, make sure you have a google account.
Skip Step 1,2 and 3 if you already did it. And just reuse the Spreadsheet you copied.
Go to this Spreadsheet: Auto Translation Spreadsheet by Hhuxx1
On the Spreadsheet you just Copied. Open the Appscript.
You need to allow the Appscripts. by Clicking the “ConvertToLuaProject” then give it Authorization by running it once. Make sure it has this specific Code
function getResult() { var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); var sheet = spreadsheet.getSheetByName('LangToTranslate'); var lastRow = sheet.getLastRow(); var lastColumn = sheet.getLastColumn(); // start from row 4 (skipping headers) var dataRange = sheet.getRange(4, 1, lastRow - 3, lastColumn); var dataValues = dataRange.getValues(); const codeLang = ["en", "cn", "tw", "tha", "esn", "ptb", "fra", "jpn", "ara", "kor", "vie", "rus", "tur", "ita", "ger", "ind", "msa"]; var result = []; for (var i = 0; i < dataValues.length; i++) { var rowData = dataValues[i]; if (rowData.some(item => item.trim() === "")) { break; } else { var rowResult = []; for (var l = 1; l < rowData.length; l++) { // Start from 1 to skip the first element in rowData rowResult.push(`createText("${codeLang[l]}","${rowData[l]}","${rowData[0]}");`); } result.push(rowResult); } } return result; }
Click “Run” then it Will Pop Up This.
Then click on Review Permission. Login to your Google Account. Once you see this screen
Click on Advanced. Then click on Go to ConvertLuaProject(unsafe)
Click on Allow
Go to Sheet named “Result”.
Then write “=getResult()” at any cell to get the result of your translation.
Don't Use the function into English Column on sheet “LangToTranslate”
Don't change the sheet “LangToTranslate” Name.
It will show Loading. Wait until the result appear. ;
After the result Appear copy the cell into your script “List of Text” File