Module:bn-headword


local export = {}
local m_scripts = require("Module:scripts")
local m_hi_pa_headword = require("Module:hi-pa-headword")

local lang = require("Module:languages").getByCode("bn")
local langname = "Bengali"

local function track(page)
	require("Module:debug").track("bn-headword/" .. page)
end

function export.show(frame)
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
	
	local params = {
		["head"] = {list = true},
		["tr"] = {list = true, allow_holes = true},
		["sort"] = {},
		["ur"] = {list = true},
		["splithyphen"] = {type = "boolean"},
	}

	local PAGENAME = mw.title.getCurrentTitle().text
	
	if PAGENAME:find(" ") then
		track("space")
	end

	if m_hi_pa_headword.pos_functions[poscat] then
		for key, val in pairs(m_hi_pa_headword.pos_functions[poscat].params) do
			params[key] = val
		end
	end

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

	local data = {
		lang = lang,
		langname = langname,
		pos_category = poscat,
		heads = args["head"],
		translits = args["tr"],
		categories = {},
		genders = {},
		inflections = {},
		sort_key = args["sort"],
	}

	if #data.translits > 0 then
		track("manual-translit/" .. poscat)
	end

	local heads = data.heads
	local auto_linked_head = require("Module:headword utilities").add_lemma_links(PAGENAME, args["splithyphen"])
	if #heads == 0 then
		data.heads = {auto_linked_head}
	else
		for _, head in ipairs(heads) do
			if head == auto_linked_head then
				track("redundant-head")
			end
		end
	end

	if m_hi_pa_headword.pos_functions[poscat] then
		m_hi_pa_headword.pos_functions[poscat].func(args, data)
	end


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

function export.common_params_doc(frame)
	local params = {
		["includeg"] = {type = "boolean"},
		["addltext"] = {},
	}

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

	local text = [=[
;{{para|head}}, {{para|head2}}, {{para|head3}}, ...
: Explicitly specified headword(s), for introducing links in multiword expressions. Note that by default each word of a multiword lemma is linked, so you only need to use this when the default links don't suffice (e.g. the multiword expression consists of non-lemma forms, which need to be linked to their lemmas).
;{{para|tr}}, {{para|tr2}}, {{para|tr3}}, ...
: Manual transliteration(s), in case the automatic transliteration is incorrect.
;{{para|sort}}
: Sort key. Rarely needs to be given.
]=]

	-- Remove final newline so template code can add a newline after invocation
	text = text:gsub("\n$", "")
	return mw.getCurrentFrame():preprocess(text)
end

return export