模組:Zh-Christian-syn

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


-- adapted from [[MOD:zh-dial-syn]]

local export = {}
local m_links = require("Module:links")
local m_languages = require("Module:languages")
local zh = m_languages.getByCode("zh")

local branch_list = {
	"Protestant", "Roman Catholic", "Eastern Orthodox", "Church of the East"
}

local branch_list_chinese = {
	["Protestant"] = "新教",
	["Roman Catholic"] = "天主教會",
	["Eastern Orthodox"] = "東正教會",
	["Church of the East"] = "景教"
}

local branch_colour = {
	["Protestant"]			= "FAF5F0",
	["Roman Catholic"]		= "F0F5FA",
	["Eastern Orthodox"]	= "F0FAF3",
	["Church of the East"]	= "F6F0FA",
}

function export.main(frame)
	local args = frame:getParent().args
	local pagename = mw.title.getCurrentTitle().text
	local target_page = args[1] or pagename
	local resource_page = "Module:zh/data/Christian-syn/" .. target_page
	local m_syndata
	if mw.title.new(resource_page).exists then
		m_syndata = require(resource_page).list
	else
		return frame:expandTemplate{ title = "Template:zh-Christian-syn/uncreated", args = { target_page } }
	end
	
	local syn_table = { [=[
		<div class="NavFrame" style="border:0px; max-width: 40em; text-align:center;"><div class="NavHead" style="font-size:105%; border:1px solid #aaaaaa; margin-left:-1px; background-color:#CCCCFF; text-align:center;" cellpadding="3">「]=] ..
			m_syndata["title"] .. '」在基督教不同分支中的譯名' ..
			[=[</div><div class="NavContent"> 
		{| class="wikitable" style="margin:0; text-align:center; width: 100%"
		|-
		! style="background:#E8ECFA" | 分支]=] .. "\n" }
	
	if m_syndata["type"] == "book" then
		table.insert(syn_table, [=[! style="background:#E8ECFA" | 譯名
			! style="background:#E8ECFA" | 縮寫]=] .. [=[
			<div style="float: right; clear: right; font-size:60%"><span class="plainlinks">[]=] ..
				tostring(mw.uri.fullUrl("Module:zh/data/Christian-syn/" .. target_page, { ["action"] = "edit" })) ..
			' 編輯]</span></div>')
	
		for _, branch in ipairs(branch_list) do
			local colour = branch_colour[branch]
			local formatted_names = {}
			local formatted_abbs = {}
			local synonym_set = m_syndata[branch] or { "" }
			
			if synonym_set[1] ~= "" then
				for i, synonym in ipairs(synonym_set) do
					local synonym_note = mw.text.split(synonym, ":")
					local syn, note = synonym_note[1], synonym_note[2]
					local link = m_links.full_link( {
							term = syn.."//",
							lang = zh,
							tr = "-"
						} )
					if note and note == "abb" then
						table.insert(formatted_abbs, link)
					else
						note = note and ' <span style="font-size:60%">' .. note .. '</span>' or ""
						table.insert(formatted_names, link .. note)
					end
				end
			
				table.insert(syn_table, "\n|-")
				table.insert(syn_table, '\n|style="background:#' .. colour .. '"| ' .. '[[' .. branch_list_chinese[branch] .. ']]\n|style="background:#' .. colour .. '"| ' .. table.concat(formatted_names, "、") .. '\n|style="background:#' .. colour .. '"| ' .. table.concat(formatted_abbs, "、"))
			end
		end
	else
		table.insert(syn_table, [=[! style="background:#E8ECFA" | 譯名]=] .. [=[
			<div style="float: right; clear: right; font-size:60%"><span class="plainlinks">[]=] ..
				tostring(mw.uri.fullUrl("Module:zh/data/Christian-syn/" .. target_page, { ["action"] = "edit" })) ..
			' 編輯]</span></div>')
	
		for _, branch in ipairs(branch_list) do
			local colour = branch_colour[branch]
			local formatted_synonyms = {}
			local synonym_set = m_syndata[branch] or { "" }
			
			if synonym_set[1] ~= "" then
				for i, synonym in ipairs(synonym_set) do
					local synonym_note = mw.text.split(synonym, ":")
					local syn, note = synonym_note[1], synonym_note[2]
					local synonym_link = m_links.full_link( {
							term = syn.."//",
							lang = zh,
							tr = "-"
						} )
					note = note and ' <span style="font-size:60%">' .. note .. '</span>' or ""
					table.insert(formatted_synonyms, synonym_link .. note)
				end
			
				table.insert(syn_table, "\n|-")
				table.insert(syn_table, '\n|style="background:#' .. colour .. '"| ' .. '[[' .. branch_list_chinese[branch] .. ']]\n|style="background:#' .. colour .. '"| ' .. table.concat(formatted_synonyms, "、"))
			end
		end
	end
	
	table.insert(syn_table, '\n|}</div></div>')
	
	return table.concat(syn_table, "")
end

return export