Jump to content

[AJUDA] Sistema de linguagem


Recommended Posts

Olá senhores, então estou querendo colocar sistema de linguagem na gamemode que estou, até consegui colocar porém, quero que quando muda a linguagem ela atualiza os textos para a linguagem escolhida, porém toda vez que mudo de linguagem tenho que relogar para trocar a linguagem e mudar os textos, tanto como o dxDrawText e o guiCreateLabel.

script que estou usando:

-- lado client

GUIEditor.label[1] = guiCreateLabel(8, 30, 103, 19, exports.DayZ:getLanguageTextClient("languagecL"), false, GUIEditor.window[1])
guiSetFont(GUIEditor.label[1], "default-bold-small")
GUIEditor.combobox[1] = guiCreateComboBox(175, 30, 177, 85, "", false, GUIEditor.window[1])

local languages = {
    en = "English",
    pt = "Portugues",
    ru = "Русский",
}

addEventHandler("onClientResourceStart",resourceRoot,function()
    if (languages) then
        local num=0;
        for i,v in pairs(languages) do
            guiComboBoxAddItem(GUIEditor.combobox[1],v)
            if i == getElementData(localPlayer,"language") then
                guiComboBoxSetSelected(GUIEditor.combobox[1],num);
            end
            num = num+1;
        end
    end
end);

function getLang(langid)
    for i,v in pairs(languages) do
        local language = guiComboBoxGetItemText(GUIEditor.combobox[1],langid)
        if (language == v) then
            return i;
        end
    end
end

function playerLogin()
	removeLogin()
	local langid = guiComboBoxGetSelected(GUIEditor.combobox[1])
	triggerServerEvent ("loginPlayerBySeral",localPlayer,localPlayer,getLang(langid))
	setCameraTarget(getLocalPlayer())
end


-- lado Server 

local pass = "546586545"
function playerJoin(language)
	account = getAccount((string.sub(getPlayerSerial(source), 25).."THS"))
	if account then
		logIn(source,account, pass)
		setElementData(source,"language",language)
	end
end
addEventHandler("onPlayerJoin", getRootElement(), playerJoin)

function loginPlayerBySeralServer(source,language)
	local theAccount = getAccount((string.sub(getPlayerSerial(source), 25).."THS"))
	if theAccount then
		if theAccount then
			setAccountPassword ( theAccount, pass )
			setElementData(source,"language",language)
			triggerEvent("onPlayerDayZLogin", getRootElement(), (string.sub(getPlayerSerial(source), 25).."THS"), source)
		else
		end
	else
		local theAccount = addAccount((string.sub(getPlayerSerial(source), 25).."THS"), pass )
		if theAccount then
			logIn(source,theAccount, pass)
			setElementData(source,"language",language)
			triggerEvent("onPlayerDayZRegister", getRootElement(), (string.sub(getPlayerSerial(source), 25).."THS"), source)
		else
		end
	end
end
addEvent("loginPlayerBySeral", true)
addEventHandler("loginPlayerBySeral", getRootElement(), loginPlayerBySeralServer)

eu uso o 

exports.DayZ:getLanguageTextClient("playL")

para chamar a tradução da tabela, a tabela:

local languages = {
	en = "English",
	pt = "Portugues",
	ru = "Русский",
}

local translation = {
-- Login
	["playL"] = {
		en = "PLAY", 
		pt = "JOGAR",
		ru = "ИГРАТЬ"
	},
	["characterL"] = {
		en = "CHARACTER", 
		pt = "PERSONAGEM",
		ru = "ХАРАКТЕР"
	},
	["settingsL"] = {
		en = "SETTINGS", 
		pt = "CONFIGURAÇÕES",
		ru = "НАСТРОЙКИ"
	},
	["exitL"] = {
		en = "EXIT", 
		pt = "SAIR",
		ru = "ВЫХОД"
	},
	
}

function getPlayerLanguage(player)
	if (not player) then outputDebugString("Player expected got '"..tostring(player).."'",1,255,0,0) return; end
	if (getElementData(player,"language")) then
		return getElementData(player,"language");
	else
		return "en";
	end
	return false;
end

function getLanguageTextClient(text)
	if (not text) then outputDebugString("String expected got '"..tostring(text).."'",1,255,0,0) return; end
	local translationText = translation[text];
	if (translationText) then
		return translationText[getPlayerLanguage(localPlayer)];
	end
	return text;
end

function getLanguageTextServer(text,player)
	if (not text) then outputDebugString("String expected got '"..tostring(text).."'",1,255,0,0) return; end
	if (not text) then outputDebugString("Player expected got '"..tostring(player).."'",1,255,0,0) return; end
	local translationText = translation[text];
	if (translationText) then
		return translationText[getPlayerLanguage(player)];
	end
	return text;
end

desde já agradeço. :)

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...