====== 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 -- Local Hosted Server result = 0 languageCode = "en" areaCountry = "ID" -- Cloud Server result = 0 languageCode = 1 areaCountry = nil Let's Jump Straight into the Tutorial ------ ===== Tutorial Auto Translation on Script ===== We will be Installing the following framework just in 2 step ==== 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|}} ----- ==== Step 2 ==== 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 ===Now you can use it easily like this example: === -- let's assume Player is from Spain -- Cannot Directly be Used before player joined the game T_Text(playerid,"Hello World") --> "Hola Mundo" ----- ===== Translating the String===== 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.// ==== Step 1 ==== Go to this Spreadsheet: [[https://docs.google.com/spreadsheets/d/1L5FzAF9We1pY3ghDl9DSiZi0Rrd7s63MgpwUxEDUTBM/edit?gid=0#gid=0|Auto Translation Spreadsheet by Hhuxx1]] ----- ==== Step 2 ==== Clone the Spreadsheet : {{:developer_center:developer_editor:script:cloningspreadsheet.png|File>Make a Copy}} ----- ==== Step 3 ==== Save it to Your Drive : {{:developer_center:developer_editor:script:makeacopyspreasheettranslation.png?400|}} ===IMPORTANT : If this is your first time using the spreadsheet.=== On the Spreadsheet you just Copied. Open the Appscript. {{:developer_center:developer_editor:script:open_the_appscript.png?600|}} **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. {{:developer_center:developer_editor:script:givingautotranslationappscriptauth.png?800|}} ----- Then click on Review Permission. Login to your **Google Account**. **Once you see this screen** {{:developer_center:developer_editor:script:warningappscriptfromhhuxx1.png?600|}} ----- Click on **Advanced**. Then click on '' Go to ConvertLuaProject(unsafe) '' {{:developer_center:developer_editor:script:trustthehhuxx1.png?600|}} ----- Click on **Allow** {{:developer_center:developer_editor:script:allowingappscript.png?400|}} ==== Step 3 ==== Write your Text in English Column. On your copied spreadsheet. {{:developer_center:developer_editor:script:exampleofthistranslation.png?600|}} ----- ==== Step 4 ==== 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. {{:developer_center:developer_editor:script:resultspreadsheet.png?600|}}; After the result Appear copy the cell into your script "List of Text" File {{:developer_center:developer_editor:script:resultlmao.png?300|}} ==== Step 5 ==== Paste into your script "List of Text" File. After the "Language Session of Player" file. {{:developer_center:developer_editor:script:translationscriptfile.png?600|}} Use **Shift + Ctrl + Right + Down ** to Block all the Result and Safely Copy it