မာတိကာသို့ ခုန်သွားရန်

မော်ဂျူး:pi-headword

ဝစ်ရှင်နရီ မှ

Documentation for this module may be created at မော်ဂျူး:pi-headword/doc

local export = {}
local pos_functions = {}
local links = require('Module:links')
local labels = require('Module:labels')

local lang = require('Module:languages').getByCode('pi')
local PAGENAME = mw.title.getCurrentTitle().text
local currentScript = lang:findBestScript(PAGENAME)

local translit = require('Module:pi-Latn-translit').tr

local Array = require "Module:array"

function export.alt(frame)

	local args = frame:getParent().args

	local currentScriptCode = currentScript:getCode()
	local availableScripts = lang:getScripts()
	local latinForm = args['Latn'] or currentScriptCode == 'Latn' and PAGENAME or error('No Latin-script form detected.')
	local scriptCode

	local terms
	local first
	local output = Array('<div class="NavFrame" style="max-width:40em"><div class="NavHead" style="background:#d9ebff">မူကွဲပုံစံများ</div><div class="NavContent" style="text-align:left"><ul>')
	for _, script in ipairs(availableScripts) do
		scriptCode = script:getCode()
		terms = { args[scriptCode], args[scriptCode..'2'], args[scriptCode..'3'],
			 args[scriptCode..'4'], args[scriptCode..'5'], args[scriptCode..'6'],
			 args[scriptCode..'7'], args[scriptCode..'8']}
		if args.hl1 and scriptCode == 'Latn' then -- Discard argument 'Latn'
			terms = {terms[2], terms[3], terms[4], terms[5], terms[6], terms[7], terms[8]}
		end
		local t1, t2, t3, t4
		t1 = translit(latinForm, scriptCode, {}) -- not affect Latn itself

		if scriptCode == 'Thai' or scriptCode == 'Laoo' then
			t2 = translit(latinForm, scriptCode, {impl='no'})
		end
-- For Lao script without implicit vowels, 'y' can also be 'ຢ', but seemingly
-- not if a Buddhist Institute consonant is used.
		if scriptCode == 'Laoo' then
			if not mw.ustring.find(t2, '[ຆຌຏຐຑຒຓຘຠຨຩ]') then
				t3 = mw.ustring.gsub(t2, 'ຍ', 'ຢ')
			end
		end

		if scriptCode == 'Mymr' then
			t2 = translit(latinForm, scriptCode, {variation='1'}) --Mon
			t3 = translit(latinForm, scriptCode, {variation='2'}) --Old Shan
			t4 = translit(latinForm, scriptCode, {variation='3'}) --New Shan
		end

		if #terms == 0 then
			terms[1] = t1
			if t2 and (t1 ~= t2) then table.insert(terms, t2) end
			if t3 and (t1 ~= t3) and (t2 ~= t3) then table.insert(terms, t3) end
			if t4 and (t1 ~= t4) and (t2 ~= t4) and (t3 ~= t4) then table.insert(terms, t4) end
		elseif terms[1] ~= t1 and terms[2] ~= t1  and terms[3] ~= t1  and terms[4] ~= t1 then
			output:insert('[[Category:Pali terms with inconsistent transliterations]]')
		end

		first = true
		for _,term in ipairs(terms) do
			if term ~= nil and term ~= PAGENAME then
				if first then
					first = false
					output:insert('<li>')
				else
					output:insert(' or ')
				end
				output:insert(links.full_link({lang = lang, sc = script, term = term, tr = '-'}))
			end
		end
		if not first then
			output:insert(' ' .. labels.show_labels {
				lang = lang,
				labels = { script:getDisplayForm() },
			} .. '</li>')
		end
	
	end
	output:insert('</ul></div></div>')

	return output:concat()

end

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 is_noun
	if poscat == "နာမ်များ" or poscat == "တစ်ဦးဆိုင်နာမ်များ" or poscat == "နာမ်စားများ" or poscat == "နာမ်ပုဒ်များ" then
		is_noun = true
		params[1] = {list = "g", default = "?"}
		params["m"] = {list = true}
		params["f"] = {list = true}
		params["n"] = {list = true}
	end
	if poscat == "ကြိယာများ" then
		params[1] = {default = "?"}
	end
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	for i, v in ipairs(args.tr) do
		if args.tr[i] == '+' then args.tr[i] = nil end
	end

	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, 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 == "ကြိယာများ" then
        table.insert(data.inflections, {label = "root", args[1]})
    end
	
	return require("Module:headword").full_headword(data)
end

return export