Module:la-headword

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
The following documentation is located at Module:la-headword/documentation. [edit]
Text-x-generic with pencil.svg This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local m_headword = require("Module:headword")
local m_utilities = require("Module:utilities")
 
local export = {}
local pos_functions = {}
 
local lang = require("Module:languages").getLanguageByCode("la")
 
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local args = frame:getParent().args
	NAMESPACE = mw.title.getCurrentTitle().nsText
	PAGENAME = mw.title.getCurrentTitle().text
 
	local head = args["head"]; if head == "" then head = nil end
 
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
 
	local genders = {}
	local inflections = {}
	local categories = {"Latin " .. poscat}
	local infl_classes = {}
 
	if pos_functions[poscat] then
		local head2 = pos_functions[poscat](args, genders, inflections, categories, infl_classes)
		head = head or head2
	end
 
	return
		m_headword.format_headword(head, lang, "Latn") ..
		m_headword.format_genders(genders, lang) ..
		m_headword.format_inflections(inflections, lang, "Latn") ..
		format_infl_classes(infl_classes) ..
		m_utilities.format_categories(categories, lang)
end
 
function format_infl_classes(infl_classes)
	if #infl_classes < 1 then
		return ""
	end
 
	for i, val in ipairs(infl_classes) do
		infl_classes[i] = "[[Appendix:Latin " .. val .. "|" .. val .. "]]"
	end
 
	return "; ''" .. table.concat(infl_classes, "/") .. "''"
end
 
pos_functions["nouns"] = function(args, genders, inflections, categories, infl_classes)
	local head = args[1]; if head == "" then head = nil end
	local gender = args[4]; if gender == "" then gender = nil end
	local gender2 = args["g2"]; if gender2 == "" then gender2 = nil end
	local genitive = args[3]; if genitive == "" then genitive = nil end
	local infl_class = args[5]; if infl_class == "" then infl_class = nil end
 
	table.insert(genders, gender)
 
	if gender2 then
		table.insert(genders, gender2)
	end
 
	if #genders == 0 then
		table.insert(genders, "?")
	end
 
	if genitive then
		table.insert(inflections, {label = "genitive", genitive})
	else
		if NAMESPACE == "Template" then
			table.insert(inflections, {label = "genitive", "genitive"})
		else
			error("Please provide the genitive.")
		end
	end
 
	if infl_class then
		table.insert(infl_classes, infl_class .. " declension")
	else
		if NAMESPACE == "Template" then
			table.insert(infl_classes, "? declension")
		else
			error("Please provide the declension class.")
		end
	end
 
	return head
end
 
return export