Module:Lang: Difference between revisions

More general check for subpage lang code
added nil check for lang code
Line 45: Line 45:
     local lang_code = title.fullText:match(".*/(.*)$")
     local lang_code = title.fullText:match(".*/(.*)$")
-- if the last part the url is two letters, then it is likely a valid lang code
-- if the last part the url is not two letters, then its not a lang code,
if (string.len(lang_code) == 2) then
-- so default to english
return lang_code
if (lang_code == nil or string.len(lang_code) ~= 2) then
return 'en'
end
end
-- default to english if none is found
     return lang_code
     return 'en'
end
end


return p
return p