Jump to content

ମଡ୍ୟୁଲ:headword/templates

ଉଇକିଅଭିଧାନ‌ରୁ

This module is used by the template {{head}} to create headwords for entries.


local export = {}

-- Part of speech types that should not be pluralized.
local invariable = {
	["cmavo"] = true,
	["cmene"] = true,
	["fu'ivla"] = true,
	["gismu"] = true,
	["Han tu"] = true,
	["hanzi"] = true,
	["hanja"] = true,
	["jyutping"] = true,
	["kanji"] = true,
	["lujvo"] = true,
	["phrasebook"] = true,
	["pinyin"] = true,
	["rafsi"] = true,
	["romaji"] = true,
}

local params = {
	[1] = {required = true, default = "und"},
	["sc"] = {},
	["cat sc"] = {},
	["sort"] = {},
	
	[2] = {},
	["cat2"] = {},
	["cat3"] = {},
	
	["head"] = {list = true, allow_holes = true, default = ""},
	["tr"] = {list = true, allow_holes = true},
	["g"] = {list = true},
	
	[3] = {list = true, allow_holes = true},
	
	["f1accel"]  = {}, ["f1request"]  = {}, ["f1alt"]  = {}, ["f1sc"]  = {}, ["f1id"]  = {}, ["f1tr"]  = {}, ["f1g"]  = {}, ["f1qual"]  = {}, ["f1nolink"]  = {type = "boolean"}, ["f1lang"]  = {},
	["f2accel"]  = {}, ["f2request"]  = {}, ["f2alt"]  = {}, ["f2sc"]  = {}, ["f2id"]  = {}, ["f2tr"]  = {}, ["f2g"]  = {}, ["f2qual"]  = {}, ["f2nolink"]  = {type = "boolean"}, ["f2lang"]  = {},
	["f3accel"]  = {}, ["f3request"]  = {}, ["f3alt"]  = {}, ["f3sc"]  = {}, ["f3id"]  = {}, ["f3tr"]  = {}, ["f3g"]  = {}, ["f3qual"]  = {}, ["f3nolink"]  = {type = "boolean"}, ["f3lang"]  = {},
	["f4accel"]  = {}, ["f4request"]  = {}, ["f4alt"]  = {}, ["f4sc"]  = {}, ["f4id"]  = {}, ["f4tr"]  = {}, ["f4g"]  = {}, ["f4qual"]  = {}, ["f4nolink"]  = {type = "boolean"}, ["f4lang"]  = {},
	["f5accel"]  = {}, ["f5request"]  = {}, ["f5alt"]  = {}, ["f5sc"]  = {}, ["f5id"]  = {}, ["f5tr"]  = {}, ["f5g"]  = {}, ["f5qual"]  = {}, ["f5nolink"]  = {type = "boolean"}, ["f5lang"]  = {},
	["f6accel"]  = {}, ["f6request"]  = {}, ["f6alt"]  = {}, ["f6sc"]  = {}, ["f6id"]  = {}, ["f6tr"]  = {}, ["f6g"]  = {}, ["f6qual"]  = {}, ["f6nolink"]  = {type = "boolean"}, ["f6lang"]  = {},
	["f7accel"]  = {}, ["f7request"]  = {}, ["f7alt"]  = {}, ["f7sc"]  = {}, ["f7id"]  = {}, ["f7tr"]  = {}, ["f7g"]  = {}, ["f7qual"]  = {}, ["f7nolink"]  = {type = "boolean"}, ["f7lang"]  = {},
	["f8accel"]  = {}, ["f8request"]  = {}, ["f8alt"]  = {}, ["f8sc"]  = {}, ["f8id"]  = {}, ["f8tr"]  = {}, ["f8g"]  = {}, ["f8qual"]  = {}, ["f8nolink"]  = {type = "boolean"}, ["f8lang"]  = {},
	["f9accel"]  = {}, ["f9request"]  = {}, ["f9alt"]  = {}, ["f9sc"]  = {}, ["f9id"] =  {}, ["f9tr"]  = {}, ["f9g"]  = {}, ["f9qual"]  = {}, ["f9nolink"]  = {type = "boolean"}, ["f9lang"]  = {},
	["f10accel"] = {}, ["f10request"] = {}, ["f10alt"] = {}, ["f10sc"] = {}, ["f10id"] = {}, ["f10tr"] = {}, ["f10g"] = {}, ["f10qual"] = {}, ["f10nolink"] = {type = "boolean"}, ["f10lang"] = {},
	["f11accel"] = {}, ["f11request"] = {}, ["f11alt"] = {}, ["f11sc"] = {}, ["f11id"] = {}, ["f11tr"] = {}, ["f11g"] = {}, ["f11qual"] = {}, ["f11nolink"] = {type = "boolean"}, ["f11lang"] = {},
	["f12accel"] = {}, ["f12request"] = {}, ["f12alt"] = {}, ["f12sc"] = {}, ["f12id"] = {}, ["f12tr"] = {}, ["f12g"] = {}, ["f12qual"] = {}, ["f12nolink"] = {type = "boolean"}, ["f12lang"] = {},
	["f13accel"] = {}, ["f13request"] = {}, ["f13alt"] = {}, ["f13sc"] = {}, ["f13id"] = {}, ["f13tr"] = {}, ["f13g"] = {}, ["f13qual"] = {}, ["f13nolink"] = {type = "boolean"}, ["f13lang"] = {},
	["f14accel"] = {}, ["f14request"] = {}, ["f14alt"] = {}, ["f14sc"] = {}, ["f14id"] = {}, ["f14tr"] = {}, ["f14g"] = {}, ["f14qual"] = {}, ["f14nolink"] = {type = "boolean"}, ["f14lang"] = {},
	["f15accel"] = {}, ["f15request"] = {}, ["f15alt"] = {}, ["f15sc"] = {}, ["f15id"] = {}, ["f15tr"] = {}, ["f15g"] = {}, ["f15qual"] = {}, ["f15nolink"] = {type = "boolean"}, ["f15lang"] = {},
	["f16accel"] = {}, ["f16request"] = {}, ["f16alt"] = {}, ["f16sc"] = {}, ["f16id"] = {}, ["f16tr"] = {}, ["f16g"] = {}, ["f16qual"] = {}, ["f16nolink"] = {type = "boolean"}, ["f16lang"] = {},
	["f17accel"] = {}, ["f17request"] = {}, ["f17alt"] = {}, ["f17sc"] = {}, ["f17id"] = {}, ["f17tr"] = {}, ["f17g"] = {}, ["f17qual"] = {}, ["f17nolink"] = {type = "boolean"}, ["f17lang"] = {},
}

function export.head_t(frame)
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	-- Get language and script information
	local lang = args[1]
	local sc = args["sc"]
	local cat_sc = args["cat sc"]
	lang = require("Module:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
	
	if cat_sc then
		cat_sc = (cat_sc and (require("Module:scripts").getByCode(cat_sc) or error("The script code \"" .. cat_sc .. "\" is not valid.")) or nil)
		sc = cat_sc
	else
		sc = (sc and (require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
	end
	
	-- Gather basic parameters
	local sort_key = args["sort"]
	local pos = args[2]
	local cat2 = args["cat2"]
	local cat3 = args["cat3"]
	local heads = args["head"]
	local translits = args["tr"]
	local genders = args["g"]
	
	-- Gather inflected forms
	local inflections = {}
	
	-- Go over all the inflection parameters
	for i = 1, math.ceil(args[3].maxindex / 2) do
		local infl_part = {
			label    = args[3][i * 2 - 1],
			accel    = args["f" .. i .. "accel"],
			request  = args["f" .. i .. "request"],
			}
		
		local form = {
			term       =  args[3][i * 2],
			alt        =  args["f" .. i .. "alt"],
			genders    = {args["f" .. i .. "g"]},
			id         =  args["f" .. i .. "id"],
			lang       =  args["f" .. i .. "lang"],
			nolink     =  args["f" .. i .. "nolink"],
			qualifiers = {args["f" .. i .. "qual"]},
			sc         =  args["f" .. i .. "sc"],
			translit   =  args["f" .. i .. "tr"],
			}
		
		if form.lang ~= nil then
			form.lang = require("Module:languages").getByCode(form.lang) or error("The language code \"" .. form.lang .. "\" is not valid.")
		end
		
		if form.sc ~= nil then
			form.sc = require("Module:scripts").getByCode(form.sc) or error("The script code \"" .. form.sc .. "\" is not valid.")
		end
		
		-- If no term or alt is given, then the label is shown alone.
		if form.term or form.alt then
			table.insert(infl_part, form)
		end
		
		if infl_part.label == "or" then
			-- Append to the previous inflection part, if one exists
			if #infl_part > 0 and inflections[1] then
				table.insert(inflections[#inflections], form)
			end
		elseif infl_part.label then
			-- Add a new inflection part
			table.insert(inflections, infl_part)
		end
	end
	
	-- Get/set categories
	local categories = {}
	local tracking_categories = {}
	
	if pos then
		if not pos:find("s$") and not invariable[pos] then
			--require("Module:debug").track("head tracking/singular category")
			
			-- Make the plural form of the part of speech
			if pos:find("x$") then
				pos = pos .. "es"
			else
				pos = pos .. "s"
			end
		end
		
		table.insert(categories, lang:getCanonicalName() .. " " .. pos .. (cat_sc and " in " .. cat_sc:getCategoryName() or ""))
	end
	
	if cat2 then
		table.insert(categories, lang:getCanonicalName() .. " " .. cat2)
	end
	
	if cat3 then
		table.insert(categories, lang:getCanonicalName() .. " " .. cat3)
	end
	
	return require("Module:headword").full_headword(lang, sc, heads, translits, genders, inflections, categories, sort_key) ..
		require("Module:utilities").format_categories(tracking_categories, lang, sort_key)
end

return export