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 = {
= "FAF0F2",
= "FAF0F2",
= "FAF0F2",
= "FAF5F0",
= "F0F5FA",
= "F0FAF3",
= "FAF0F6",
= "FAF9F0",
= "FAF5F0",
= "FAF0FE",
= "F7FAF0",
= "F7FAF0",
= "F7FAF0",
= "F7FAF0",
= "F7FAF0",
= "F7FAF0",
= "F7FAF0",
= "F0F5FA",
= "F0F5FA",
= "FAF0F6",
= "F0FAF6",
= "F4F0FA",
= "F0F2FA",
}
local special_note = {
= "]",
= "Formal <small>(])</small>",
= "Taxonomic name",
}
function export.main(frame)
local data = {}
local args = frame:getParent().args
local pagename = mw.title.getCurrentTitle().text
local target_page = args 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 and m_syndata ~= "" and m_syndata or target_page
local main_title = m_links.full_link( { term = title:gsub("", "") .. "//", lang = zh, tr = "-" } )
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">Dialectal synonyms of ]=] ..
main_title .. ' (“' .. m_syndata .. '”) ' ..
"]\n' .. [=[</div><div class="NavContent">
{| class="wikitable" style="margin:0; text-align:center; width: 100%"
|-
! style="background:#E8ECFA" | Variety
! style="background:#E8ECFA" | Location
! style="background:#E8ECFA" | Words]=] .. [=[
<div style="float: right; clear: right; font-size:60%"><span class="plainlinks">=] ..
tostring(mw.uri.fullUrl("Module:zh/data/dial-syn/" .. target_page, { = "edit" })) ..
' edit]</span></div>' }
local note = m_syndata
if m_syndata == "" then
data = { target_page }
elseif m_syndata == "-" then
data = nil
else
data = m_syndata
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 = 0
end
for i = 1,#m_dialdata,1 do
loc = m_dialdata
cur = m_syndata or {""}
if cur == "" then
exists = false
else
exists = true
variety = loc.group
variety_count = variety_count + 1
end
end
for i = 1,#exists,1 do
if exists then
loc = m_dialdata
variety = loc.group
location_name = (loc.english or loc.key):gsub("(%(.*%))", "<small>%1</small>")
location_link = loc.link or loc.key
mw.log(loc.key)
for i, synonym in ipairs(m_syndata) do
local synonym_note = mw.text.split(synonym, ":")
local synonym_etym = mw.text.split(synonym_note, "_")
local syn, etym, note = synonym_etym, synonym_etym, synonym_note
local synonym_link = m_links.full_link( {
term = syn .. (etym and string.format("#Etymology %s", etym) or "") .. "//",
alt = etym and (syn .. string.format("<sub>%s</sub>", etym)) .. "//",
lang = zh,
tr = "-"
} )
if note == "GT" then
require('Module:debug/track')("zh-dial-GT")
end
note = note and ' <span style="font-size:60%"><i>' .. note .. '</i></span>' 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
table.insert(syn_table, "\n!rowspan=" .. variety_count .. (special_note and " colspan=2" or "") ..
' style="background:#' .. colour .. '"| ' .. (special_note or variety))
end
table.insert(syn_table,
((location_name and not special_note) and ('\n|style="background:#' .. colour .. '"| ' ..
']') 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" | ' ..
"<small>Note</small>\n| colspan=2|<small><i>" .. note .. "</i></small>")
end
table.insert(syn_table, '\n|}</div></div>')
return table.concat(syn_table, "")
end
return export