Module:Lang: Difference between revisionsGive feedback
Jump to navigation
Jump to search
swapped argument order |
Added retrieval of lang code from subpage name |
||
| Line 14: | Line 14: | ||
p.get_string = function(frame) | p.get_string = function(frame) | ||
local key = frame.args[1] | local key = frame.args[1] | ||
local | local lang_code_override = frame.args[2] | ||
local lang_code = lang_code_override | |||
if (lang_code_override == '') then | |||
lang_code = get_lang_code() | |||
end | |||
local data = get_lang_file(lang_code) | local data = get_lang_file(lang_code) | ||
if (data == nil) then | if (data == nil) then | ||
return string.format("Language code '%s' not found", lang_code) | return string.format("Language file for code '%s' not found", lang_code) | ||
end | end | ||
| Line 34: | Line 39: | ||
local lang_code = frame.args[2] | local lang_code = frame.args[2] | ||
local data = get_lang_file(lang_code) | local data = get_lang_file(lang_code) | ||
end | |||
function get_lang_code() | |||
local title = mw.title.getCurrentTitle() | |||
local lang_code = title.fullText:match(".*/(.*)$") | |||
-- ensure language code is valid | |||
local valid_codes = {'en', 'fr'} | |||
if string_in_list(lang_code, valid_codes) then | |||
return lang_code | |||
end | |||
-- default to english if none is found | |||
return 'en' | |||
end | |||
function get_effects(ability, used_keys) | |||
effects = {} | |||
for key, value in pairs(ability) do | |||
if not string_in_list(key, used_keys) then | |||
local effect_value = string.format("'''%s''': %s", key, value) | |||
table.insert(effects, effect_value) | |||
end | |||
end | |||
return effects | |||
end | |||
function string_in_list(str, list) | |||
for _, value in ipairs(list) do | |||
if value == str then | |||
return true | |||
end | |||
end | |||
return false | |||
end | end | ||
return p | return p | ||