มอดูล: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" border="0" cellpadding="5" cellspacing="0" style="border:1px solid #aaaaaa; margin-left:5px; margin-right:10px; text-align:center;" rules="all" frame="box"]=],
	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_form },
					["ราชาศัพท์"] = { 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", mw.ustring.upper) ..
				"\n| " ..
				table.concat(hash, "<br>"))
		end
		table.insert(result, fmt.footer)
	
	end
	return table.concat(result)
end

return export