Module:Lang: Difference between revisionsGive feedback
Return empty string if key not found |
m get_string_fallback |
||
| Line 29: | Line 29: | ||
if (label == nil) then | if (label == nil) then | ||
return '' | return '' | ||
end | |||
return label | |||
end | |||
-- Get a localized string by the raw key, return fallback string if unable to be localized | |||
p.get_string_fallback = function(frame) | |||
local key = frame.args[1] | |||
local fallback = frame.args[2] | |||
local lang_code = get_lang_code() | |||
local data = get_lang_file(lang_code) | |||
if (data == nil) then | |||
return string.format("Lang code '%s' does not have a json file", lang_code) | |||
end | |||
local label = data[key] | |||
if (label == nil) then | |||
return fallback | |||
end | end | ||