Module:za

From Wiktionary, the free dictionary
Jump to navigation Jump to search
This module page is experimental.
The details of its operation have not yet been fully decided upon. Do not deploy widely until the module page is finished.

local export = {}
local gsub = mw.ustring.gsub

local function genPoS(text)
	local pos = {
		[""] = "noun", ["n"] = "noun", ["pn"] = "proper noun", ["propn"] = "proper noun", ["pron"] = "pronoun",
		["v"] = "verb", ["a"] = "adjective", ["adj"] = "adjective", ["adv"] = "adverb",
		["prep"] = "preposition", ["postp"] = "postposition", ["conj"] = "conjunction",
		["part"] = "particle", ["pref"] = "prefix", ["suf"] = "suffix",
		["prov"] = "proverb", ["id"] = "idiom", ["ph"] = "phrase", ["intj"] = "interjection", ["interj"] = "interjection",
		["cl"] = "classifier", ["cls"] = "classifier", ["num"] = "numeral", ["abb"] = "abbreviation", ["deter"] = "determiner"
	}
	return pos[text] or text
end

--modified from [[MOD:th]]
function export.new(frame)
	local title = mw.title.getCurrentTitle().text
	local args = frame:getParent().args
	local pos = genPoS(args[1] or "")
	local def = args[2] or "{{rfdef|za}}"
	local etym = args["e"] or false
	local head = args["head"] or false
	local saw = args["saw"] or false
	local cls = args["cls"] or false
	local cat = args["cat"] or false
	local wp = args["wp"] or false
	
	local result = {}
	
	local function other(class, title, args)
		local code = ""
		if args[class] then
			code = code .. "\n\n===" .. title .. "===\n{{col3|za|" .. 
				table.concat(mw.text.split(args[class], ","), "|")
			i = 2
			while args[class .. i] do
				code = code .. "|" .. args[class .. i]
				i = i + 1
			end
			code = code .. "}}"
		end
		return code
	end
	
	table.insert(result, "==Zhuang==")
	if wp then table.insert(result, "\n{{wikipedia" .. (wp ~= "y" and "|" .. wp or "") .. "|lang=za}}") end
	
	table.insert(result, other("alt", "Alternative forms", args))
	
	if etym then table.insert(result, "\n\n===Etymology===\n" .. etym) end
	
	table.insert(result, "\n\n===Pronunciation===\n* {{za-pron}}")
	
	local pos_title = gsub(pos, "^.", mw.ustring.upper)
	table.insert(result, "\n\n===" .. pos_title .. "===\n{{za-head|" .. pos ..
		(head and ("|head=" .. head) or "") ..
		(saw and ("|" .. saw) or "") ..
		((cls and pos == "noun") and "|cls=" .. cls or "") .. "}}\n\n# " .. def)
	
	table.insert(result, other("syn", "=Synonyms=", args))
	table.insert(result, other("ant", "=Antonyms=", args))
	table.insert(result, other("der", "=Derived terms=", args))
	table.insert(result, other("rel", "=Related terms=", args))
	table.insert(result, other("also", "=See also=", args))
	
	if cat then table.insert(result, "\n\n{{C|za|" .. cat .. "}}") end
	
	return table.concat(result)
end

return export