Module:zh-glyph

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

local eras = { { "Shang", { "bronze-shang", "oracle" } }, { "Western Zhou", { "bronze", "oracle-zhouyuan" } }, { "Spring and Autumn", { "bronze-spring" } }, { "Warring States", { "bronze-warring", "silk", "slip" } }, { "Shuowen Jiezi (compiled in Han)", { "zhou", "ancient", "odd", "seal", "vulgar" } }, { "Hanjian (compiled in Song)", { "hanjian" } }, { "Guwen Sishengyun (compiled in Song)", { "GWSSY" } }, { "Jizhuan Guwen Yunhai (compiled in Song)", { "JZGWYH" } }, { "Liushutong (compiled in Ming)", { "bigseal" } }, { "Libian (compiled in Qing)", { "clerical" } }, { "Tang Stone Classics", { "kai-Kaicheng" } }, { "Kangxi Dictionary (compiled in Qing)", { "mingti-Kangxi" } }, }

local scripts = { ["bronze-shang"] = "Bronze inscriptions", ["oracle"] = "Oracle bone script", ["oracle-zhouyuan"] = "Oracle bone script", ["bronze"] = "Bronze inscriptions", ["bronze-spring"] = "Bronze inscriptions", ["bronze-warring"] = "Bronze inscriptions", ["silk"] = "Chu slip and silk script", ["slip"] = "Qin slip script", ["zhou"] = "Shizhoupian script", ["ancient"] = "Ancient script", ["odd"] = "Odd character", ["seal"] = "Small seal script", ["vulgar"] = "Vulgar character", ["bigseal"] = "Transcribed ancient scripts", ["hanjian"] = "Transcribed ancient scripts", ["GWSSY"] = "Transcribed ancient scripts", ["JZGWYH"] = "Transcribed ancient scripts", ["clerical"] = "Clerical script", ["kai-Kaicheng"] = "Regular script", ["mingti-Kangxi"] = "Ming typeface", }

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

local script_abbrev = { ["B"] = "bronze", ["b"] = "bronze", ["31"] = "bronze", ["32"] = "bronze", ["33"] = "bronze", ["34"] = "bronze", ["j"] = "oracle", ["41"] = "oracle", ["42"] = "oracle", ["43"] = "oracle", ["51"] = "silk", ["52"] = "silk", ["53"] = "silk", ["71"] = "slip", ["Q"] = "slip", ["S"] = "silk", ["s"] = "seal", ["27"] = "seal", ["L"] = "bigseal", }

function export.main(frame) local params = { [1] = {},		["no_img"] = {type = "boolean"}, ["no_phon"] = {type = "boolean"}, }	local args, invalid_args, invalid_args_warning = require("Module:checkparams").process(frame:getParent, params) 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 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 = target_page .. "-" .. 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;\"|") 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 for _, img in ipairs(data_module[1]) do table.insert(char_data[script_abbrev[sub(img, 1, 1)]], ' ACC-' .. img ..				'.svg ' .. img .. '  ') end for i, script in ipairs(hide_scripts) do			if char_data[script][1] then if i ~= 1 then table.insert(hideText, " ") end table.insert(hideText, " " .. scripts[script] .. " " .. table.concat(char_data[script]) .. " ") end end table.insert(hideText, '\n|- class="vsHide"\n| width="100%" align="left" colspan="' .. (count == 0 and 1 or count) ..			'|\n References:' ..			' \nMostly from Richard Sears\' ' ..			"..			target_page .. " Chinese Etymology site (authorisation), 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). ")	end

if ( success or count > 0 ) and not frame:getParent.args["no_img"] then

glyph_forms = "\n" .. [=[{| class="wikitable zh-glyph]=] .. (success and ' vsSwitcher" data-toggle-category="forms' or "") ..			[=[" cellpadding=7 style="border-spacing: 1px; border: 1px solid darkgray; text-align:center" ! class="vsToggleElement" colspan="]=] .. (count == 0 and 1 or count) ..			[=[" |Historical forms of the character ]=] .. target_page .. [=[ ]=] ..

(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|}\n "

else glyph_forms = "" end

local phonText = {} local list = mw.loadData("Module:zh-glyph/phonetic/list") phonComp = list[target_page] or nil

if phonComp and not frame:getParent.args["no_phon"] then table.insert(phonText,			'\n' ..			' ' ..			'' ..			'Characters in the same phonetic series' ..			' ( ' .. phonComp .. ' )' ..			' (Zhengzhang, 2003) ' ..			' ' ..			' ' ..			'\n{| class="wikitable zh-glyph" style="margin-top: 0; width: 100%; display: table;"' ..			'\n|-\n! align="center"|\n!Old Chinese'		)

local phonData = mw.loadData("Module:zh-glyph/phonetic") local m_och = require("Module:och-pron").retrieve_pron

for item in mw.text.gsplit(phonData[phonComp], "") do table.insert(phonText, '\n|-\n| align="center" | ' .. item .. ' ') local IPA = m_och(item, nil, true) if IPA then table.insert(phonText, '\n| ' .. IPA .. ' ') end end table.insert(phonText, '\n|}\n ') end

return glyph_forms .. table.concat(phonText) .. invalid_args_warning end

return export