Module:id-headword

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module deploys the Indonesian headword templates and all associated templates.


local export = {}
local pos_functions = {}

local lang = require("Module:languages").getByCode("id")
local script = require('Module:scripts').getByCode("Latn")
local PAGENAME = mw.title.getCurrentTitle().text

function export.show(frame)
	-- FIXME: Use [[Module:parameters]].
	local args = frame:getParent().args
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")

	local head = args["head"]; if head == "" then head = nil end
	
	local data = {lang = lang, sc = script, pos_category = poscat, categories = {}, heads = {head}, translits = {"-"}, inflections = {}}
	
	if pos_functions[poscat] then
		pos_functions[poscat](args, data)
	end

	return require("Module:headword").full_headword(data)

end

pos_functions["nouns"] = function(args, data)

	local pl = {label = "plural"}
	if args["pl"] == nil then
		table.insert(data.categories, "Requests for plural forms in Indonesian entries")
	else
		if args["pl"] == "-" then
			table.insert(data.categories, "Indonesian uncountable nouns")
		else
			if args["pl"] == "duplication" then
				-- common plural
				local subwords = mw.text.split(PAGENAME, "%s")
				local firstword = subwords[1]
				subwords[1] = mw.ustring.gsub("[[" .. firstword .. "]]-[[" .. firstword .. "]]", "([a-z]+%-)%1%1", "banyak %1") -- reduplicate only first word
				table.insert(pl, table.concat(subwords, " "))
			else
				table.insert(pl, args["pl"]) -- this is also used for 'para' type
				if args["pl2"] then table.insert(pl, args["pl2"]) end
				if args["pl3"] then table.insert(pl, args["pl3"]) end
			end
			table.insert(data.inflections, pl)
		end
	end
	
	local ku = {label = "first-person possessive"}
	if args["ku"] ~= "-" or args["ku"] == nil then
		table.insert(data.inflections, ku)
		table.insert(ku, mw.ustring.format("%s[[-ku|ku]]", PAGENAME))
	end

	local mu = {label = "second-person possessive"}
	if args["mu"] ~= "-" or args["mu"] == nil then
		table.insert(data.inflections, mu)
		table.insert(mu, mw.ustring.format("%s[[-mu|mu]]", PAGENAME))
	end

	local nya = {label = "third-person possessive"}
	if args["nya"] ~= "-" or args["nya"] == nil then
		table.insert(data.inflections, nya)
		table.insert(nya, mw.ustring.format("%s[[-nya|nya]]", PAGENAME))
	end

end

pos_functions["proper nouns"] = function(args, data)

	local pl = {label = "plural"}
	-- not necessary to have plural(s)
	if args["pl"] then table.insert(pl, args["pl"]) end
	if args["pl2"] then table.insert(pl, args["pl2"]) end
	if args["pl3"] then table.insert(pl, args["pl3"]) end
	if #pl > 0 then table.insert(data.inflections, pl) end

end

pos_functions["adjectives"] = function(args, data)

end

return export