Sendy Posted March 13, 2019 Share Posted March 13, 2019 (edited) Hello can anyone help me with this? i want create multi language but i don't know how. --en.xml <language name="EN"> <message string="EN" /> <message string="EN1" /> </language> i'am using if getElementData(source, "Language") == "EN" then outputChatBox("EN") else outputChatBox("EN1") end --for set language setElementData(source, "Language", "EN") How i can get text in outputChatBox from first code? please help Edited March 13, 2019 by Sendy Link to comment
XaskeL Posted March 13, 2019 Share Posted March 13, 2019 di usually use message keys, not the message itself for translation. I don’t really like Xml so I’ll show an example on Lua Tables local __locale = { ["en"] = { ["welcome_message"] = "Hello, brother!", }, ["ru"] = { ["welcome_message"] = "Привет, брат!", } } addEventHandler("onPlayerJoin", root, function() local lang = getElementData(source, "Language") outputChatBox(__locale[lang]["welcome_message"], source, 0, 255, 0, true) end ); 1 Link to comment
Sendy Posted March 13, 2019 Author Share Posted March 13, 2019 (edited) I need from .xml but thanks i find this from another resource but i don't know how this can work with my system function loadText (language, stringName, resource) if resource == nil then stringsFile = stringsRootFile else local resourceFile = getResourceFromName (resource) if resourceFile == false then return false end end language = getElementData(source, "Language") if stringName then stringsFile = xmlLoadFile (":" .. tostring(resource) .. "/en.xml") if stringsFile then local firstStringNode = xmlFindChild ( stringsFile, tostring(stringName), 0 ) if firstStringNode then local secondStringNode = xmlFindChild ( firstStringNode, tostring(language), 0 ) if secondStringNode then local text = xmlNodeGetValue (secondStringNode) if text then return tostring(text) else return false end else return false end else return false end else return false end else return false end end Edited March 13, 2019 by Sendy Link to comment
XaskeL Posted March 13, 2019 Share Posted March 13, 2019 27 minutes ago, Sendy said: Мне нужно из .xml, но спасибо, я нашел это из другого ресурса, но я не знаю, как это может работать с моей системой Give me full resource/gamemode where did gets this Link to comment
Sendy Posted March 13, 2019 Author Share Posted March 13, 2019 2 minutes ago, XaskeL said: Give me full resource/gamemode where did gets this https://community.multitheftauto.com/index.php?p=resources&s=details&id=2175 Link to comment
XaskeL Posted March 13, 2019 Share Posted March 13, 2019 3 hours ago, Sendy said: https://community.multitheftauto.com/index.php?p=resources&s=details&id=2175 This is a ready resource, as I understood loadText is responsible for loading data about translations from * .xml, look at the resource, there should be examples. Also in the description of the resource shows how to display the text. Link to comment
holuzs Posted March 15, 2019 Share Posted March 15, 2019 sendMessage(target player, "English text", "Russian text") function sendMessage(writeTo, enText, ruText) if getElementData(writeTo, "language")=="english" then outputChatBox(enText, writeTo, 255, 255, 255, true) elseif getElementData(writeTo, "language")=="russian" then outputChatBox(ruText, writeTo, 255, 255, 255, true) end end Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now