Module:Langcode

-- See Template:langcode

local p = {} -- p stands for package

function p.langcode( frame ) local title = mw.title.getCurrentTitle local subjectspace = title.subjectNsText

if string.len(subjectspace) == 2 then return string.lower(subjectspace) -- dedicated language namespace end

local pos = string.find(title.text,':') if pos == nil then return 'en' -- assume English if no colon end

local pseudonamespace = string.sub(title.text,1,pos-1) local langcode = frame.args[pseudonamespace] -- language passed as argument

if langcode then return langcode else return string.lower(pseudonamespace) -- pseudonamespace is language end end

return p