Module:Lang: Difference between revisionsGive feedback
Jump to navigation
Jump to search
added nil check for lang code |
m search_string finished |
||
| Line 37: | Line 37: | ||
p.search_string = function(frame) | p.search_string = function(frame) | ||
local key = frame.args[1] | local key = frame.args[1] | ||
local | local lang_code_override = frame.args[2] | ||
local data = get_lang_file(lang_code) | |||
local lang_code = lang_code_override | |||
if (lang_code_override == '') then | |||
lang_code = get_lang_code() | |||
end | |||
-- Load the language files | |||
local data_en = get_lang_file('en') -- English data | |||
local data_lang = get_lang_file(lang_code) -- Target language data | |||
-- Search for the key in the English data | |||
local key = nil | |||
for k, v in pairs(data_en) do | |||
if v == label then | |||
key = k -- Find the key corresponding to the label | |||
break | |||
end | |||
end | |||
-- If the key is found, return the localized string, otherwise return a fallback | |||
if key and data_lang[key] then | |||
return data_lang[key] | |||
else | |||
return "English label not found or not localized" | |||
end | |||
end | end | ||