模組:Mn-headword

維基詞典,自由的多語言詞典


local export = {}

local lang = require("Module:languages").getByCode("mn")
local mn = require("Module:mn-common")

local params = {
	["head"] = {}, --with no diacritics I don't think we'll need more than one head
	["cat"] = {list = true},
	[1] = {list = true}
}

local function get_script(args) 
	return lang:findBestScript(args["head"] or mw.title.getCurrentTitle().subpageText)
end
	
local function otherscript(inflections, args, sc, categories)
	if #args[1] < 1 then
		if sc then
			if sc:getCode() == "Mong" then
			end
		end
		return 
	end

	local other_sc
	
	local scripts = {
		m = "Mong",
		c = "Cyrl",
		Mong = true,
		Cyrl = true,
	}
	if scripts[args[1][1]] then
		other_sc =  require("Module:scripts").getByCode(scripts[args[1][1]])
		table.remove(args[1], 1)
		require("Module:debug").track("mn-headword/script-param")
	else
		other_sc = lang:findBestScript(args[1][1])
	end
	
	if sc and sc:getCode() == other_sc:getCode() then
		error("The headword and the alternative spelling should be in different scripts.")
	end
	
	local spelling = {label = other_sc:getCanonicalName() .. "寫法", sc = other_sc, enable_auto_translit=true}
	
	for i, arg in ipairs(args[1]) do
		table.insert(spelling, arg)
	end
	
	table.insert(inflections, spelling)
end

local function categorize(args)
	local cats = args["cat"]
	local categories = {}
	if cats then
		for i, arg in ipairs(cats) do
			table.insert(categories, lang:getCanonicalName() .. arg)
		end
	end
	if (args["head"] or mw.title.getCurrentTitle().subpageText):find(" ") then
		table.insert(categories, lang:getCanonicalName() .. "多字詞")
	elseif mw.ustring.sub( mw.title.getCurrentTitle().subpageText, 1, 1 ) ~= "-" and get_script(args):getCode() == "Cyrl" then
		table.insert(categories, lang:getCanonicalName() .. #mn.syllables( mw.title.getCurrentTitle().subpageText ) .. "音節詞" )
	end
	return categories
end

function export.basic(frame)
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local inflections = {}
	local categories = categorize(args)
	
	local sc = get_script(args)
	
	otherscript(inflections, args, sc, categories)
	
	local data = {lang = lang, sc = sc, heads = {args["head"]}, genders = nil, inflections = inflections, pos_category = frame.args[1], categories = categories, sort_key = nil}
	return require("Module:headword").full_headword(data)
end

function export.noun(frame)

	params["pl"] = {list = true}
	params["dec"] = {}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local sc = get_script(args)
	
	local inflections = {}
	
	local categories = categorize(args)
	
	local declension = ""
	
	otherscript(inflections, args, sc, categories)
	
	if #args["pl"] > 0 then
		local plurals = {label = "定複數"}
		for i, pl in ipairs(args["pl"]) do
			table.insert(plurals, pl)
		end
		table.insert(inflections, plurals)
	end

		
--	if args["dec"] then  --此部分需要補充翻譯,暫時隱藏
--		declension = "; <small><i>("
--		if args["dec"] == "r" then
--			declension = declension .. "規則變格"
--			table.insert(categories, lang:getCanonicalName() .. "規則變格名詞")
--		elseif args["dec"] == "n" then
--			declension = declension .. "hidden-n 變格"
--			table.insert(categories, lang:getCanonicalName() .. "hidden-n 變格名詞")
--		elseif args["dec"] == "g" then
--			declension = declension .. "hidden-g 變格"
--			table.insert(categories, lang:getCanonicalName() .. "hidden-g 變格名詞")
--		elseif args["dec"] == "m" then
--			declension = declension .. "混合變格"
--			table.insert(categories, lang:getCanonicalName() .. "混合變格名詞")
--		else
			--error("non-existent declension")
--		end
--		declension = declension .. ")</i></small>"
--	end
	
	local data = {lang = lang, sc = sc, heads = {args["head"]}, genders = nil, inflections = inflections, pos_category = "名詞", categories = categories, sort_key = nil}
	return require("Module:headword").full_headword(data) .. declension
end


function export.verb(frame)
	params["caus"] = {list = true}
	params["pass"] = {list = true}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	
	local inflections = {}
	local categories = categorize(args)
	
	local sc = get_script(args)
	
	otherscript(inflections, args, sc, categories)
	
	if #args["caus"] > 0 then
		causatives = {label = "使役態"}
		for i, x in ipairs(args["caus"]) do
			table.insert(causatives, x)
		end
		table.insert(inflections, causatives)
	end
	
	if #args["pass"] > 0 then
		passives = {label = "被動態"}
		for i, x in ipairs(args["pass"]) do
			table.insert(passives, x)
		end
		table.insert(inflections, passives)
	end

	local data = {lang = lang, sc = sc, heads = {args["head"]}, genders = nil, inflections = inflections, pos_category = "動詞", categories = categories, sort_key = nil}
	return require("Module:headword").full_headword(data)
end


return export