Jump to content

Language


TorNix~|nR

Recommended Posts

Hello guys, I wanted to ask if I can set this languages in buttons

if (getElementData(localPlayer, "Language") == "English")
if (getElementData(localPlayer, "Language") == "Spanish")

this is the button

guiCreateButton(0, 0, 0, 0, "Police", false, panel)

I'm wondering how to change the button from English to Spanish, any ideas please?

I mean changing that "Police" to "Policía" (Spanish Language).

Edited by TorNix~|nR
Link to comment
  • Moderators
27 minutes ago, TorNix~|nR said:

I'm wondering how to change the button from English to Spanish, any ideas please?

 

You could try this, not tested. But it is a start.

local languageSwitch = {}

local defaultLanguage = "nl"

function guiSetLangaugeSupport (element, languages)
	languageSwitch[#languageSwitch + 1] = {element = element, languages = languages}

	guiSetText(element, languages[defaultLanguage] or guiGetText(element))

	return element
end

function guiSetLanguageSwitch (language)
	for i=1, #languageSwitch do
		local switchData = languageSwitch[i]
		guiSetText(switchData.element, switchData[language] or switchData[defaultLanguage] or select(2, next(switchData)) or guiGetText(switchData.element))
	end
end


 

switchData[language] or -- The option you want

switchData[defaultLanguage] or -- default language

select(2, next(switchData)) or -- First possible item

guiGetText(switchData.element) -- previous text

;O

 

local button = guiSetLangaugeSupport(guiCreateButton(0, 0, 0, 0, "", false, panel), {en = "Police", nl = "Politie"})

 

 

Edited by IIYAMA
  • Like 1
Link to comment

Thank you so much, I just tested it, the defaultLanguage is working fine

but I want to know how to get the language I have

Like I told you I am using this

if (getElementData(localPlayer, "Language") == "English")
if (getElementData(localPlayer, "Language") == "Spanish")

I made this when the player join, he select the language (English or Spanish)

if you understand what I mean

  • Confused 1
Link to comment

I'm sorry if it's confusing, I mean
For example

{en = "Police", es = "Policía"})

I want the "es" to get

(getElementData(localPlayer, "Language") == "Spanish")

and the "en" to get

(getElementData(localPlayer, "Language") == "English")

 

Edited by TorNix~|nR
Link to comment
  • Moderators
7 minutes ago, TorNix~|nR said:

I'm sorry if it's confusing, I mean

 

{Spanish = "policía", English = "Police"}

You could swap es with Spanish, does that help?

 

 


guiSetLanguageSwitch (getElementData(localPlayer, "Language")) -- call the function

 

local defaultLanguage = "Spanish"

 

Edited by IIYAMA
Link to comment
local languageSwitch = {}

local defaultLanguage = "English"

function guiSetLangaugeSupport (element, languages)
	languageSwitch[#languageSwitch + 1] = {element = element, languages = languages}

	guiSetText(element, languages[defaultLanguage] or guiGetText(element))

	return element
end

function guiSetLanguageSwitch (language)
	for i=1, #languageSwitch do
		local switchData = languageSwitch[i]
		guiSetText(switchData.element, switchData[language] or switchData[defaultLanguage] or select(2, next(switchData)) or guiGetText(switchData.element))
	end
end

guiSetLanguageSwitch (getElementData(localPlayer, "Language"))

local button = guiSetLangaugeSupport(guiCreateRadioButton(17, 27, 205, 21, "Police", false, panel), {Spanish = "policía", English = "Police"})

@IIYAMA I'm sorry but I'm a complete failure :/

Link to comment
  • Moderators
12 minutes ago, TorNix~|nR said:

guiSetLanguageSwitch (getElementData(localPlayer, "Language"))

It is the moment of switching languages.

It should at least be executed after creating the button. Now it is executed before that.

Try to run this line with a command handler or with onClientResourceStart. (that is if you know if the value is set before that)

 

 

 

 

Link to comment

I used this

local languageSwitch = {}

local defaultLanguage = "English"

function guiSetLangaugeSupport (element, languages)
	languageSwitch[#languageSwitch + 1] = {element = element, languages = languages}

	guiSetText(element, languages[defaultLanguage] or guiGetText(element))

	return element
end

function guiSetLanguageSwitch (language)
	for i=1, #languageSwitch do
		local switchData = languageSwitch[i]
		guiSetText(switchData.element, switchData[language] or switchData[defaultLanguage] or select(2, next(switchData)) or guiGetText(switchData.element)) -------THE PROBLEM
	end
end

local button = guiSetLangaugeSupport(guiCreateRadioButton(17, 27, 205, 21, "Police", false, panel), {Spanish = "policía", English = "Police"})

addEventHandler( "onClientResourceStart", getRootElement( ),
    function ()
        guiSetLanguageSwitch (getElementData(localPlayer, "Language"))
    end
);

but I got this problem

Bad argument @'guiSetText' [Expected string at argument 2, got table]

Edited by TorNix~|nR
Link to comment
  • Moderators
9 hours ago, TorNix~|nR said:

Bad argument @'guiSetText' [Expected string at argument 2, got table]

You need to index one more time with .languages, before you index with the actually language you want.

 

1. So:

switchData.languages[language]

 

2. Same goes for the other lines that make use of that table.

switchData.langauges[defaultLanguage]

select(2, next(switchData.languages))

 

Edited by IIYAMA
Link to comment

I used this

local languageSwitch = {}

local defaultLanguage = "Spanish"

function guiSetLangaugeSupport (element, languages)
	languageSwitch[#languageSwitch + 1] = {element = element, languages = languages}

	guiSetText(element, languages[defaultLanguage] or guiGetText(element))

	return element
end

function guiSetLanguageSwitch (language)
	for i=1, #languageSwitch do
		local switchData = languageSwitch[i]
		guiSetText(switchData.languages[language] or switchData.langauges[defaultLanguage] or select(2, next(switchData.languages)) or guiGetText(switchData.element)) -----------HEREAGAIN
	end
end

local button = guiSetLangaugeSupport(guiCreateRadioButton(17, 27, 205, 21, "Police", false, panel), {Spanish = "policía", English = "Police"})

addEventHandler( "onClientResourceStart", getRootElement(),
    function ()
        guiSetLanguageSwitch (getElementData(localPlayer, "Language"))
    end
);

and got the problem in the same line

guiSetText [Expected gui-element at argument 1, got string 'Police']

 

Link to comment
  • Moderators
29 minutes ago, TorNix~|nR said:

I'm sorry again but I didn't understand how

I changed every element to button, I tried panel too

but it's the same problem

 

 

Before (without element):

guiSetText(switchData.languages[language] or switchData.langauges[defaultLanguage] or select(2, next(switchData.languages)) or guiGetText(switchData.element))

 

After (with element):

guiSetText(switchData.element, switchData.languages[language] or switchData.langauges[defaultLanguage] or select(2, next(switchData.languages)) or guiGetText(switchData.element))

 


Also please stop putting confusing reactions on most of my replies, it marks them as confusing in general while most of them are not. Sure, I do not mind, if my reply does not make sense at all. You could using emotions in your own replies instead, that makes more sense.

@TorNix~|nR

Edited by IIYAMA
  • Thanks 1
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...