Module:User:Wpi/zh-dial-syn

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

local variety_list = { "Classical", "Formal", "Taxonomic", "Mandarin", "Cantonese", "Gan", "Hakka", "Huizhou", "Jin", "Jiuxing Yumin", "Northern Min", "Eastern Min", "Southern Min", "Puxian Min", "Central Min", "Shaojiang Min", "Zhongshan Min", "Southern Pinghua", "Northern Pinghua", "Shehua", "Waxiang", "Wu", "Xiang" }

local variety_colour = { ["Classical"]		= "FAF0F2", ["Formal"]			= "FAF0F2", ["Taxonomic"]		= "FAF0F2", ["Mandarin"]		= "FAF5F0", ["Cantonese"]		= "F0F5FA", ["Gan"]				= "F0FAF3", ["Hakka"]			= "FAF0F6", ["Huizhou"]			= "FAF9F0", ["Jin"]				= "FAF5F0", ["Jiuxing Yumin"]	= "FAF0FE", ["Northern Min"]	= "F7FAF0", ["Eastern Min"]		= "F7FAF0", ["Southern Min"]	= "F7FAF0", ["Puxian Min"]		= "F7FAF0", ["Central Min"]		= "F7FAF0", ["Shaojiang Min"]	= "F7FAF0", ["Zhongshan Min"]	= "F7FAF0", ["Southern Pinghua"]= "F0F5FA", ["Northern Pinghua"]= "F0F5FA", ["Shehua"]			= "FAF0F6", ["Waxiang"]			= "F0FAF6", ["Wu"]				= "F4F0FA", ["Xiang"]			= "F0F2FA", }

local special_note = { ["Classical"] = "Classical Chinese", ["Formal"] = "Formal (Written Standard Chinese) ", ["Taxonomic"] = "Taxonomic name", }

function export.main(frame) local data = {} local args = frame:getParent.args local pagename = mw.title.getCurrentTitle.text local target_page = args[1] or pagename local resource_page = "Module:zh/data/dial-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-dial/uncreated", args = { target_page } } end --allow alternative title linking for sum-of-parts tables local title = m_syndata["title"] and m_syndata["title"] ~= "" and m_syndata["title"] or target_page local main_title = m_links.full_link( { term = title:gsub("[0-9%-]", "") .. "//", lang = zh, tr = "-" } ) local syn_table = { [=[ Dialectal synonyms of ]=] .. main_title .. ' (“' .. m_syndata["meaning"] .. '”) ' .. " &#91;map&#93; \n' .. [=[ 	{| class="wikitable" style="margin:0; text-align:center; width: 100%" |-	! style="background:#E8ECFA" | Variety ! style="background:#E8ECFA" | Location ! style="background:#E8ECFA" | Words]=] .. [=[	 []=] ..		tostring(mw.uri.fullUrl("Module:zh/data/dial-syn/" .. target_page, { ["action"] = "edit" })) .. ' edit] ' } local note = m_syndata["note"] if m_syndata["Formal"][1] == "" then data["Formal"] = { target_page } elseif m_syndata["Formal"][1] == "-" then data["Formal"] = nil else data["Formal"] = m_syndata["Formal"] end

local m_dialdata = require("Module:User:Wpi/zh/data/dial") local variety = "" local current_variety = "" local location_name = "" local location_link = "" local colour = "" local exists = {} local variety_count = {} local formatted_synonyms = {} local loc = {} local cur = {} for i, v in pairs(variety_list) do		variety_count[v] = 0 end

for i = 1,#m_dialdata,1 do		loc = m_dialdata[i] cur = m_syndata[loc.key] or {""} if cur[1] == "" then exists[i] = false else exists[i] = true variety = loc.group variety_count[variety] = variety_count[variety] + 1 end end for i = 1,#exists,1 do		if exists[i] then loc = m_dialdata[i] variety = loc.group location_name = (loc.english or loc.key):gsub("(%(.*%))", " %1 ") location_link = loc.link or loc.key mw.log(loc.key) for i, synonym in ipairs(m_syndata[loc.key]) do				local synonym_note = mw.text.split(synonym, ":") local synonym_etym = mw.text.split(synonym_note[1], "_") local syn, etym, note = synonym_etym[1], synonym_etym[2], synonym_note[2] local synonym_link = m_links.full_link( {						term = syn .. (etym and string.format("#Etymology %s", etym) or "") .. "//",						alt = etym and (syn .. string.format("%s", etym)) .. "//",						lang = zh,						tr = "-"					} ) if note == "GT" then require('Module:debug/track')("zh-dial-GT") end note = note and ' ''' .. note .. ''' ' or "" table.insert(formatted_synonyms, synonym_link .. note) end table.insert(syn_table, "\n|-") if variety ~= current_variety then current_variety = variety colour = variety_colour[variety] table.insert(syn_table, "\n!rowspan=" .. variety_count[variety] .. (special_note[variety] and " colspan=2" or "") .. 				' style="background:#' .. colour .. '"| ' .. (special_note[variety] or variety)) end table.insert(syn_table,				((location_name and not special_note[variety]) and ('\n|style="background:#' .. colour .. '"| ' .. 				 .. location_name .. ) or '') ..				'\n|style="background:#' .. colour .. '"| ' ..				table.concat(formatted_synonyms, ", ")) end end if note and note ~= "" then table.insert(syn_table, '\n|-\n! style="background:#FFF7FB; padding-top:5px; padding-bottom: 5px" | ' ..			" Note \n| colspan=2| " .. note .. " ") end table.insert(syn_table, '\n|} ') return table.concat(syn_table, "") end

return export