Jump to content

MultiLanguage


Sendy

Recommended Posts

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 by Sendy
Link to comment

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
);

 

  • Thanks 1
Link to comment

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 by Sendy
Link to comment
27 minutes ago, Sendy said:

Мне нужно из .xml, но спасибо, :( я нашел это из другого ресурса, но я не знаю, как это может работать с моей системой
 


 
	    

	
		  
		  
			 
		
	
  
	
      
		
			     
			
				     
				
					  
					
						 
					
						 
					
				
					 
				
			
				 
			
		
			 
		
	
		 
	

 

Give me full resource/gamemode where did gets this

Link to comment
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...