(Translated by https://www.hiragana.jp/)
模組:zh-glyph - 維基辭典 とべ內容

ぐみ:zh-glyph

維基辭典じてん

呢個ぐみ解說かいせつ以喺ぐみ:zh-glyph/docひらく

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

local eras = {
	{ "[[w:yue:しょう (くに)|しょう]]", { "bronze-shang", "oracle" } },
	{ "[[w:yue:西にしあまね|西にしあまね]]", { "bronze" } },
	{ "[[w:yue:春秋しゅんじゅう|春秋しゅんじゅう]]", { "bronze-spring" } },
	{ "[[w:yue:戰國せんごく|戰國せんごく]]", { "bronze-warring", "silk", "slip" } },
	{ "かん《[[w:yue:せつぶんかい|せつぶんかい]]》", { "zhou", "ancient", "odd", "seal", "vulgar" } },
	{ "あきら六書りくしょみつる》", { "bigseal" } },
	{ "きよし《隸辨》)", { "clerical" } }
}

local scripts = {
	["bronze-shang"] = "[[w:yue:しょうかなえぶん|金文きんぶん]]",
	["oracle"] = "[[w:yue:かぶとこつぶん|かぶとこつぶん]]",
	["bronze"] = "[[w:yue:しょうかなえぶん|金文きんぶん]]",
	["bronze-spring"] = "[[w:yue:しょうかなえぶん|金文きんぶん]]",
	["bronze-warring"] = "[[w:yue:しょうかなえぶん|金文きんぶん]]",
	["silk"] = "[[w:yue:簡|すわえけい簡帛文字もじ]]",
	["slip"] = "[[w:yue:簡|しんけい簡牘文字もじ]]",
	["zhou"] = "籀文",
	["ancient"] = "古代こだい文字もじ",
	["odd"] = "Odd character",
	["seal"] = "[[w:yue:小篆しょうてん|小篆しょうてん]]",
	["vulgar"] = "Vulgar character",
	["bigseal"] = "つてしょう",
	["clerical"] = "[[w:yue:隸書れいしょ|隸書れいしょ]]",
}

local hide_scripts = { "oracle", "bronze", "seal", "bigseal" }

local script_abbrev = {
	["B"] = "bronze",
	["b"] = "bronze",
	["j"] = "oracle",
	["S"] = "silk",
	["Q"] = "slip",
	["s"] = "seal",
	["L"] = "bigseal",
}

function export.main(frame)
	local args = frame:getParent().args
	local pagename = mw.title.getCurrentTitle().subpageText
	local target_page = args[1] or pagename
	local showEras, showScripts, showImgs, hideText = {}, {}, {}, {}
	local success, data_module = pcall(mw.loadData, "Module:zh/data/glyph-data/" .. target_page)
	
	local char_data = {
		["bronze"] = {},
		["oracle"] = {},
		["silk"] = {},
		["slip"] = {},
		["seal"] = {},
		["bigseal"] = {},
	}
	
	count = 0
	table.sort(scripts, function(first, second) return first[1] < second[1] end)
	if not frame:getParent().args["no_img"] then
		for _, era in ipairs(eras) do
			local count_era = 0
			for _, script in ipairs(era[2]) do
				local img_link = pagename .. "-" .. script .. ".svg"
				local img_file = mw.title.new("Media:" .. img_link)
				if img_file.exists and not img_file.isRedirect then
					count = count + 1
					count_era = count_era + 1
					table.insert(showScripts, "\n!" .. scripts[script])
					table.insert(showImgs, "\n| style=\"padding: 8px;\"|[[File:" .. img_link .. "|60px]]")
				end
			end
			if count_era > 0 then
				table.insert(showEras, "\n! colspan=\"" .. count_era .. "\"|" .. era[1])
			end
		end
	end
	if success then
		local img_count = 0
		for _, img in ipairs(data_module[1]) do
			img_count = img_count + 1
		end
		success = success and mw.title.new("Media:ACC-" .. data_module[1][img_count] .. ".svg").exists
	end
	if success then
		local capacity = 8
		for _, img in ipairs(data_module[1]) do
			table.insert(char_data[script_abbrev[sub(img, 1, 1)]], '<td><div class="gallerybox"' ..
				'>\n<div style="text-align:center; padding:8px" class="thumb">[[File:ACC-' .. img .. 
				'.svg|60px]]\n<div class="gallerytext">\n<p><small>' .. img .. '</small></p>\n</div>\n</div>\n</div>\n</td>')
		end
		for _, script in ipairs(hide_scripts) do
			if char_data[script][1] then
				local script_concat = { "\n----\n<table class=\"gallery\">\n<caption><b>", scripts[script], "</b></caption>\n" }
				script_data = char_data[script]
				for i = 0, math.ceil(#script_data / capacity) - 1 do
					table.insert(script_concat, "<tr>")
					for j = 1, capacity do
						table.insert(script_concat, script_data[i*capacity+j] or nil)
					end
					table.insert(script_concat, "</tr>")
				end
				table.insert(script_concat, "\n</table>")
				table.insert(hideText, table.concat(script_concat))
			end
		end
		table.insert(hideText, '\n|- class="vsHide"\n| width="100%" align="left" colspan="' .. (count == 0 and 1 or count) ..
			'|\n----<div class="toccolours mw-collapsible mw-collapsed"><b>參考さんこう</b>:' ..
			'<div class="mw-collapsible-content">\nMostly from Richard Sears\' ' .. 
			"[http://hanziyuan.net/#" ..
			target_page .. " Chinese Etymology site] ([[c:Commons:Ancient Chinese characters/Richard Sears Agreement" ..
			"|authorisation]]),<br>which in turn draws data from various collections of ancient forms of Chinese characters" ..
			", including:\n* ''Shuowen Jiezi'' (small seal), \n* ''Jinwen Bian'' (bronze inscriptions)" ..
			", \n* ''Liushutong'' (Liushutong characters) and \n* ''Yinxu Jiaguwen Bian'' (oracle bone script).</div></div>")
	end

	if success or count > 0 then
		
		glyph_forms = [=[{| class="wikitable]=] .. (success and " vsSwitcher vsToggleCategory-forms" or "") ..
			[=[" cellpadding=7 style="border-spacing: 1px; border: 1px solid darkgray; text-align:center"
			! class="vsToggleElement" colspan="]=] .. (count == 0 and 1 or count) ..
			[=[" |「<span lang="zh-Hant" class="Hani">]=] .. target_page .. [=[</span>」ふるとき嘅寫ほう]=] .. 
			
			(count > 0
				and "\n|-" .. table.concat(showEras) .. "\n|-" .. table.concat(showScripts) .. "\n|-" .. table.concat(showImgs)
				or "") ..
			
			(success
				and "\n|- class=\"vsHide\"\n| align=\"center\" colspan=\"" .. (count == 0 and 1 or count) ..
					"|" .. table.concat(hideText, "")
				or "") ..
			
			"\n|}"
			
	else
		glyph_forms = ""
	end
	
	local phonText = {}
	local list = mw.loadData("Module:zh-glyph/phonetic/list")
	phonComp = list[target_page] or nil
	
	if phonComp then
		table.insert(phonText, '\n{| class="wikitable mw-collapsible mw-collapsed" cellpadding="6" style="text-align:center"')
		table.insert(phonText, '\n|-\n! style="background-color:#F3F7F2; padding: 5px 10px 5px 10px;" colspan=2|喺同一個語音系列嘅字(<span style="font-size:120%"><span class="Hani">[[' .. phonComp .. ']]</span></span>)<small>(ていちょう,2003)</small>&nbsp; ')
		
		local phonData = mw.loadData("Module:zh-glyph/phonetic")
		local m_och = require("Module:och-pron").retrieve_pron
		
		table.insert(phonText, '\n|-\n! align="center"|\n!上古じょうこ漢語かんご')
		
		for item in mw.text.gsplit(phonData[phonComp], "") do
			table.insert(phonText, '\n|-\n| align="center" style="font-size:120%"|<span class="Hani">[[' .. item .. '#官話かんわ|' .. item .. ']]</span>')
			local IPA = m_och(item, nil, true)
			if IPA then
				table.insert(phonText, '\n|<small><span class="IPA">' .. IPA .. '</span></small>')
			end
		end
		table.insert(phonText, '\n|}')
	end
	
	return glyph_forms .. table.concat(phonText)
end

return export