Module:Wp/bcc/languages/templates

From Wikimedia Incubator

Documentation for this module may be created at Module:Wp/bcc/languages/templates/doc

local export = {}

function export.exists(frame)
	local args = frame.args
	local lang = args[1] or error("Language code has not been specified. Please pass parameter 1 to the module invocation.")
	
	lang = require("Module:Wp/bcc/languages").getLanguageByCode(lang)
	
	if lang then
		return "1"
	else
		return ""
	end
end

-- Used by accelerated creation [[WT:ACCEL]]
function export.lookup(frame)
	local args = frame.args
	local lang = args[1] or error("Language code has not been specified. Please pass parameter 1 to the module invocation.")
	local itemname = args[2] or error("Type of information to look up has not been specified. Please pass parameter 2 to the module invocation.")
	
	lang = require("Module:Wp/bcc/languages").getLanguageByCode(lang)
	
	-- The item that the caller wanted to look up
	if itemname == "names" then
		local index = args[3]; if index == "" then index = nil end
		if index then index = tonumber(index) end
		
		if (index or 1) == 1 then
			return lang:getCanonicalName()
		else
			return lang:getAllNames()[index] or ""
		end
	elseif itemname == "type" then
		return lang:getType()
	elseif itemname == "family" then
		return lang:getFamily():getCode()
	elseif itemname == "translit_module" then
		local m_languages_old = mw.loadData("Module:Wp/bcc/languages/alldata")
		return m_languages_old[lang:getCode()].translit_module or ""
	elseif itemname == "transliterate" then
		local text = args[3]; if text == "" then text = nil end
		local sc = args[4]; if sc == "" then sc = nil end
		return lang:transliterate(text, sc) or ""
	elseif itemname == "scripts" then
		local index = args[3]; if index == "" then index = nil end
		if index then index = tonumber(index) end
		
		local m_languages_old = mw.loadData("Module:Wp/bcc/languages/alldata")
		return m_languages_old[lang:getCode()].scripts[index or 1] or ""
	elseif itemname == "category_name" then
		return lang:getCategoryName()
	else
		error("Requested invalid item name \"" .. itemname .. "\".")
	end
end

return export