มอดูล:pi-headword

จาก วิกิพจนานุกรม พจนานุกรมเสรี
local export = {}
local pos_functions = {}
local links = require("Module:links")
local labels = require("Module:labels")

local u = mw.ustring.char
local lang = require("Module:languages").getByCode("pi")
local PAGENAME = mw.title.getCurrentTitle().text
local currentScript = lang:findBestScript(PAGENAME)

--Removed alt function to Module:pi-alt

function export.show(frame)
	local params = {
		["head"] = {list = true},
		["tr"] = {list = true, allow_holes = true, default = "-"},
	}
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
	-- หมวดหมู่เป็นภาษาไทย
	local poscat_th = require("Module:utilities").translate_term(poscat)

	local is_noun
	if poscat_th == "คำนาม" or poscat_th == "คำวิสามานยนาม" or poscat_th == "คำสรรพนาม" or poscat_th == "รูปผันคำนาม" then
		is_noun = true
		params[1] = {list = "g", default = "?"}
		params["m"] = {list = true}
		params["f"] = {list = true}
		params["n"] = {list = true}
	end
	if poscat_th == "คำกริยา" then
		params[1] = {default = "?"}
	end

	local args = require("Module:parameters").process(frame:getParent().args, params)

	local heads = args.head
	if #heads == 0 then
		heads = {PAGENAME}
	end
	local genders = {}
	if is_noun then
		genders = args[1]
	end

	local data = {lang = lang, sc = currentScript, pos_category = poscat_th, categories = {},
		sccat = true, heads = heads, genders = genders, inflections = {}, translits = args.tr
	}

	if is_noun then
		if #args.m > 0 then
			args.m.label = "เพศชาย"
			table.insert(data.inflections, args.m)
		end
		if #args.f > 0 then
			args.f.label = "เพศหญิง"
			table.insert(data.inflections, args.f)
		end
		if #args.n > 0 then
			args.n.label = "เพศกลาง"
			table.insert(data.inflections, args.n)
		end
		if #args.m > 0 or #args.f > 0 or #args.n > 0 then
			table.insert(data.categories, "Pali nouns with other-gender equivalents")
		end
	end
    if poscat_th == "คำกริยา" then
        table.insert(data.inflections, {label = "ธาตุ", args[1]})
    end

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

return export