Module:bo-registers

From Wiktionary, the free dictionary
Jump to navigation Jump to search

See {{bo-registers}}.


local export = {}
local m_register_data = mw.loadData("Module:bo-registers/data")
local m_links = require("Module:links")
local lang = require("Module:languages").getByCode("bo")

local fmt = {
	header = [=[{| class="floatright wikitable" style="text-align: center;"]=],
	footer = "\n|}",
}

local correspondences = {
	{ "མགོ", "དབུ" },
	{ "ལྕེ", "ལྗགས" },
	{ "མགྲིན", "མགུལ" },
	{ "ལག", "ཕྱག" },
	{ "སྣ", "ཤངས" },
	{ "ལུས", "སྐུ" },
	{ "རྣ", "སྙན" },
	{ "མིག", "སྤྱན" },
	{ "སྙིང", "ཐུགས" },
	{ "སོ", "ཚེམས" },
	{ "རྐང", "ཞབས" },
	{ "ཁ", "ཞལ" },
	{ "སྐད", "བཀའ" },
	{ "ཆུ", "ཆབ" },
	{ "རྟ", "ཆིབས" },
	{ "མིང", "མཚན" },
	{ "ཤ", "སཀར" },
	{ "ཤ", "སྐྲུམ" },
	{ "རོ", "སྤུར" },
}

function export.show(frame)
	local args = frame:getParent().args
	local p, result = {}, {}
	local pagename = mw.title.getCurrentTitle().text
	if args[1] then
		for index, item in ipairs(args) do
			table.insert(p, (item ~= "") and item or nil)
		end
	else
		table.insert(p, "xxx")
	end
	
	for _, meaning in ipairs(p) do
		local alt, sc, id, annotations, self_link = nil, nil, nil, nil, nil
		data = m_register_data[meaning] or nil
		
		if not data then
			local plain_set, honorific_set = {}, {}
			for word in mw.text.gsplit(pagename, "་") do
				local plain, honorific = word, word
				for _, set in ipairs(correspondences) do
					plain = mw.ustring.gsub(plain, "^" .. set[2] .. "$", set[1])
					honorific = mw.ustring.gsub(honorific, "^" .. set[1] .. "$", set[2])
				end
				table.insert(plain_set, plain)
				table.insert(honorific_set, honorific)
			end
			plain_form = table.concat(plain_set, "་")
			honorific_form = table.concat(honorific_set, "་")
			
			if plain_form == honorific_form then
				error("The sense “" .. meaning .. "” is not found in [[Module:bo-registers/data]].")
			else
				data = {
					["plain"] = { plain_form },
					["honorific"] = { honorific_form },
				}
			end
		end
			
		table.insert(result, fmt.header .. (meaning ~= "xxx" and ("\n|+ “" .. meaning .. "”") or ""))
		for label, words in pairs(data) do
			local hash = {}
			for _, word in ipairs(words) do
				table.insert(hash, m_links.full_link({ lang = lang, term = word }))
			end
			table.insert(result, 
				"\n|-\n! " .. 
				mw.ustring.gsub(label, "(%l)(%w*)", function(a,b) return mw.ustring.upper(a)..b end) ..
				"\n| " ..
				table.concat(hash, "<br>"))
		end
		table.insert(result, fmt.footer)
	
	end
	return table.concat(result)
end

return export