I'm trying to add multilingual support to my addon, but I've run into a problem with my language tables. Below is how I have the different phrases saved in the language file; if I set them equal to a string it works great but trying to set them equal to a table doesn't work. It complete ignores it and leaved it out.
config.Language = {}
config.Language["English"]["Close"] = "Close" -- Works fine
config.Language["English"]["Kinds"] = {'cat', 'dog'} -- Doesn't work
Upon printing the table in the server console, "Kinds" does not appear. However, typing the same thing into the server console using lua_run, it works perfectly and shows up. I can't seem to figure this one out.
How do you use this table in printing?
In the actual addon it is supposed to be used in a for loop to compare a user input to a list of possible strings, however it spits an error about it being nil. In my testing, I use
lua_run PrintTable(config.Language["English"])
and it doesn't show up.
What's nil? Show us the code where you use config.Language.
Its still nil; Close shows up but Kinds is no where to be found.
You need first to create table config, then create table config.Language, then config.Language["English"] and only after that config.Language["English"]["Kinds"]
I've done this... But only strings appear while tables never appear, its like it is completely ignored.
Do you have same things as in the post above mine?
Yes, just for clarification, I'll list it again
config = {}
config.Language = {}
config.Language["English"] = {
["Close"] = "Close",
["Kinds"] = {"cat", "dog"}
}
Now show how are you trying to use it
function IsValidKind(kind)
local tbl = config.Language["English"]["Kinds"]
for k, v in pairs(tbl) do
if v == kind then
return true
elseif #tbl == k then
return false
end
end
end
function AnotherOne(ply, kind)
if !IsValidKind(kind) then return end
-- more logic here
end
Are they in the same realm?
Yes, the language config is shared while the functions are server-sided.
Make debug:
print near (you can do inside function too) your serverside function: print(config,config.Language,config.Language["English"])
Show your results here later
Thanks for all of your help, I've solved the problem. For some reason, giving the function a local variable set to he config works while writing out the config variable does not.
-- example
local config = config.Language
function IsValidKind(kind)
local tbl = config["English"]["Kinds"]
for k, v in pairs(tbl) do
if v == kind then
return true
elseif #tbl == k then
return false
end
end
end
Just in case you want to access the original 'config' table, you should rename your local variable to something else.
Sorry, you need to Log In to post a reply to this thread.