このモジュールについての説明文ページを モジュール:利用者:Alexandr3126/test/headword/templates/doc に作成できます

local export = {}

function export.head_t(frame)
	local plain_param = {}
	local list_with_holes = {list = true, allow_holes = true}
	local boolean_list_with_holes = {list = true, allow_holes = true, type = "boolean"}
	local params = {
		[1] = {required = true, default = "und"},
		["sc"] = plain_param,
		["sort"] = plain_param,
		["jsort"] = plain_param,
		
		[2] = {required = true, default = "名詞"},
		["sccat"] = {type = "boolean"},
		["noposcat"] = {type = "boolean"},
		["nomultiwordcat"] = {type = "boolean"},
		["nogendercat"] = {type = "boolean"},
		["autotrinfl"] = {type = "boolean"},
		["cat2"] = plain_param,
		["cat3"] = plain_param,
		["cat4"] = plain_param,
		["cat5"] = plain_param,
		["cat6"] = plain_param,
		["cat7"] = plain_param,
		["cat8"] = plain_param,
		["cat9"] = plain_param,
		["cat10"] = plain_param,
		
		["head"] = {list = true, allow_holes = true, default = ""},
		["id"] = plain_param,
		["tr"] = list_with_holes,
		["ts"] = list_with_holes,
		["kanji"] = list_with_holes,
		["hanja"] = list_with_holes,
		["hanzi"] = list_with_holes,
		["Han tu"] = list_with_holes,
		["g"] = {list = true},
		
		[3] = list_with_holes,
		
		["f=accel-form"]     = list_with_holes,
		["f=accel-translit"] = list_with_holes,
		["f=accel-lemma"]    = list_with_holes,
		["f=accel-lemma-translit"] = list_with_holes,
		["f=accel-gender"]   = list_with_holes,
		["f=accel-nostore"]  = boolean_list_with_holes,
		["f=request"]        = list_with_holes,
		["f=alt"]            = list_with_holes,
		["f=sc"]             = list_with_holes,
		["f=id"]             = list_with_holes,
		["f=tr"]             = list_with_holes,
		["f=g"]              = list_with_holes,
		["f=qual"]           = list_with_holes,
		["f=autotr"]         = boolean_list_with_holes,
		["f=nolink"]         = boolean_list_with_holes,
		["f=lang"]           = list_with_holes,
	}
	
	local args = require("モジュール:parameters").process(frame:getParent().args, params)
	
	-- "eng" --> "en"
	local lang = require("モジュール:languages").code3_to_code2(args[1])
	
	-- Get language and script information
	local data = {}
	data.lang = require("モジュール:languages").getByCode(lang) or require("モジュール:languages").err(lang)
	data.sort_key = args["sort"] or (args["jsort"] and require("モジュール:ja").jsort(args["jsort"]))
	data.heads = args["head"]
	data.id = args["id"]
	data.translits = args["tr"]
	data.transcriptions = args["ts"]
	data.kanji = args["kanji"] or args["hanja"] or args["hanzi"] or args["Han tu"]
	data.genders = args["g"]
	
	-- Script
	data.sc = args["sc"] and require("モジュール:scripts").getByCode(args["sc"], "sc") or nil
	data.sccat = args["sccat"]

	-- Part-of-speech category
	data.pos_category = mw.loadData("モジュール:headword/English to Japanese")[args[2]] or args[2]
	data.noposcat = args["noposcat"]
	
	if cat_sc then
		data.pos_category = data.pos_category .. " in " .. cat_sc:getCategoryName()
	end
	
	-- Additional categories
	data.categories = {}
	data.nomultiwordcat = args["nomultiwordcat"]
	data.nogendercat = args["nogendercat"]
	
	if args["cat2"] then
		table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat2"])
	end
	
	if args["cat3"] then
		table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat3"])
	end
	
	if args["cat4"] then
		table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat4"])
	end
	
	if args["cat5"] then
		table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat5"])
	end
	
	if args["cat6"] then
		table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat6"])
	end
	
	if args["cat7"] then
		table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat7"])
	end
	
	if args["cat8"] then
		table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat8"])
	end
	
	if args["cat9"] then
		table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat9"])
	end
	
	if args["cat10"] then
		table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat10"])
	end
	
	-- Inflected forms
	data.inflections = {enable_auto_translit = args["autotrinfl"]}
	
	for i = 1, math.ceil(args[3].maxindex / 2) do
		local infl_part = {
			label    = args[3][i * 2 - 1],
			accel    = args["faccel-form"][i] and {
				form      = args["faccel-form"][i],
				translit  = args["faccel-translit"][i],
				lemma     = args["faccel-lemma"][i],
				lemma_translit = args["faccel-lemma-translit"][i],
				gender    = args["faccel-gender"][i],
				nostore   = args["faccel-nostore"][i],
			} or nil,
			request  = args["frequest"][i],
			enable_auto_translit = args["fautotr"][i],
		}
		
		local form = {
			term       =  args[3][i * 2],
			alt        =  args["falt"][i],
			genders    =  args["fg"][i] and mw.text.split(args["fg"][i], ",") or {},
			id         =  args["fid"][i],
			lang       =  args["flang"][i],
			nolink     =  args["fnolink"][i],
			qualifiers = {args["fqual"][i]},
			sc         =  args["fsc"][i],
			translit   =  args["ftr"][i],
		}
		
		if form.lang then
			form.lang = require("モジュール:languages").getByCode(form.lang) or require("モジュール:languages").err(form.lang, "f" .. i .. "lang")
		end
		
		if form.sc then
			form.sc = require("モジュール: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 data.inflections[1] then
				table.insert(data.inflections[#data.inflections], form)
			end
		elseif infl_part.label then
			-- Add a new inflection part
			table.insert(data.inflections, infl_part)
		end
	end
	
	return require("モジュール:headword").full_headword(data)
end

return export