မဝ်ဂျူ:mak-headword

နူ ဝိက်ရှေန်နရဳ
ထာမ်ပလိက်တဏအ်ဒးနွံကဵုလိက်စၟတ်သမ္တီမချူလဝ်သာဓက။
သ္ပဂုန်တုဲထာမ်ပလိက်တဏအ်ဒးစၟတ်သမ္တီကဵုလိက်မချူလဝ်နူကဵုဓမံက်ထ္ၜးကဵုဗီုပြၚ်ကိစ္စမရန်တၟအ်လဝ် ကဵု ပရေၚ်မရပ်စပ်လ္တူမုက်လိက်နကဵုလိက်စၟတ်သမ္တီမချူလဝ်သာဓက

local export = {}

local lang = require("Module:languages").getByCode("mak")


local function otherscript(inflections, args)
	local title = mw.title.getCurrentTitle()
	local sc = require("Module:scripts").findBestScript(title.subpageText, lang)
	
	local other_sc
	
	if sc:getCode() == "Latn" then
		other_sc = "Maka"
	elseif sc:getCode() == "Maka" then
		other_sc = "Latn"
	end
	
	other_sc = require("Module:scripts").getByCode(other_sc)
	local inflection = {label ="မလိက်ခ္ဍံက်" ..  other_sc:getCanonicalName() }
	
	for i, head in ipairs(args["head"]) do
		if head == "" then
			head = title.subpageText
		end
		
		local tr = args["tr"][i]
		
		if not tr then
			tr = require("Module:mak-translit").tr(require("Module:links").remove_links(head), "mak", sc:getCode())
		end
		
		table.insert(inflection, {term = tr, sc = other_sc})
	end
	
	table.insert(inflections, inflection)
end

-- The main entry point.
function export.show(frame)

    local PAGENAME = mw.title.getCurrentTitle().text

    local poscat = frame.args[1] or error(
                       "Part of speech has not been specified. Please pass parameter 1 to the module invocation.")

    local params = {
        [1] = {list = "head", allow_holes = true, default = ""},
        ["head"] = {default = ""}
    }

	local args, unused_keys = make_unused_key_tracker(frame:getParent().args)

    -- Gather parameters
    local data = {
        lang = lang,
        pos_category = poscat,
        categories = {},
        heads = {},
        translits = {},
        inflections = {}
    }

    otherscript(data.inflections, args)

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

    local unused_key_list = require"Module:table".keysToList(unused_keys)
    if #unused_key_list > 0 then
        local unused_key_string = require "Module:array"(unused_key_list):map(
                                      function(key)
                return "|" .. key .. "=" .. args[key]
            end):concat("\n")
        error("Unused arguments: " .. unused_key_string)
    end

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

local function getargs(args, argpref, position)
    -- Gather parameters
    local forms = {}

    if ine(args[position]) then
        form = ine(args[position])
    else
        form = ine(args[argpref])
    end

    local i = 1

    while form do

        table.insert(forms, {term = form})

        i = i + 1
        form = ine(args[argpref .. i])
    end

    return forms
end

local function handle_infl(args, data, argpref, label, position)
    local newinfls = getargs(args, argpref, position)
    newinfls.label = label

    if #newinfls > 0 then table.insert(data.inflections, newinfls) end
end

pos_functions["ကြိယာ"] = {
    func = function(args, data)
        data.pos_category = "ကြိယာ"
        handle_infl(args, data, "st", "ကြိယာ-မွဲကရေက်", 1)
    end
}

return export