Module:Langcode

From OpenStreetMap Wiki
Jump to navigation Jump to search
[Create] Documentation
-- 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.rootText,':')
	if pos == nil then
		return 'en' -- assume English if no colon
	end

	local pseudonamespace = string.sub(title.rootText,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