Module:Lang: Difference between revisions

Jump to navigation Jump to search
Added retrieval of lang code from subpage name
More general check for subpage lang code
Line 44: Line 44:
     local title = mw.title.getCurrentTitle()
     local title = mw.title.getCurrentTitle()
     local lang_code = title.fullText:match(".*/(.*)$")
     local lang_code = title.fullText:match(".*/(.*)$")
   
    -- ensure language code is valid
-- if the last part the url is two letters, then it is likely a valid lang code
    local valid_codes = {'en', 'fr'}
if (string.len(lang_code) == 2) then
if string_in_list(lang_code, valid_codes) then
return lang_code
return lang_code
end
end
 
-- default to english if none is found
-- default to english if none is found
     return 'en'
     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