Module:Lang: Difference between revisions

Sur (talk | contribs)
m fixed bug where get_string params were overwritten by local declaration
Sur (talk | contribs)
m all alternate get_string functions removed, now all work within main get_string
Line 79: Line 79:
label = mw.ustring.lower(label)
label = mw.ustring.lower(label)
end
end
end
return label
end
p.test = function(frame)
return p.get_string('CitadelCategoryWeapon', 'en')
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
return label
end
--Get a localized string by the raw key, and remove %variable% from key
p.get_string_remove_var = function(frame)
local key = frame.args[1]
local spaces = 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]
label = util_module.remove_var(label, spaces)
return label
end
-- get_string, but for internal use by other modules
p._get_string = function(key, lang_override)
lang_code = get_lang_code()
local data = get_lang_file(lang_override or lang_code)
if (data == nil) then
return nil
end
local label = data[KEY_OVERRIDES[key] or key]
if (label == nil) then
return nil
end
end