มอดูล:zh-dial-syn
หน้าตา
- This module lacks a documentation subpage. Please create it.
- Useful links: subpage list • links • transclusions • testcases • sandbox
local export = {}
local m_links = require("Module:links")
local m_languages = require("Module:languages")
local lang_obj = {
["zh"] = m_languages.getByCode("zh"),
["dng"] = m_languages.getByCode("dng"),
["nan-hbl"] = m_languages.getByCode("nan-hbl")
}
export.variety_list = {
"Classical", "Formal", "Taxonomic",
"Northeastern Mandarin", "Jilu Mandarin", "Jiaoliao Mandarin",
"Central Plains Mandarin", "Lanyin Mandarin",
"Southwestern Mandarin", "Jianghuai Mandarin",
"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", "Xiangnan Tuhua", "Yuebei Tuhua"
}
export.variety_list_th = {
["Classical"]="คลาสสิก", ["Formal"]="ทางการ", ["Taxonomic"]="ชื่ออนุกรมวิธาน",
["Northeastern Mandarin"]="จีนกลางตะวันออกเฉียงเหนือ", ["Jilu Mandarin"]="จีนกลางแบบจี้หลู่", ["Jiaoliao Mandarin"]="จีนกลางแบบเจียวเหลียว",
["Central Plains Mandarin"]="จีนกลาง", ["Lanyin Mandarin"]="จีนกลางแบบหลันอิ๋น",
["Southwestern Mandarin"]="จีนกลางตะวันตกเฉียงใต้", ["Jianghuai Mandarin"]="จีนกลางแบบเจียงหวย",
["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"]="เซียง", ["Xiangnan Tuhua"]="TuhuaแบบXiangnan", ["Yuebei Tuhua"]="TuhuaแบบYuebei"
}
export.variety_colour = {
-- READ BEFORE EDITING:
-- 1. You must use colours from the palette so the template looks
-- good in dark mode. See [[MediaWiki:Gadget-Palette/table]]
-- 2. These colours are duplicated in [[Module:zh-pron]].
-- Make sure the two lists are kept in sync.
["Classical"] = "var(--wikt-palette-grey-scarlet-1, #FAF0EC)",
["Formal"] = "var(--wikt-palette-grey-scarlet-1, #FAF0EC)",
["Taxonomic"] = "var(--wikt-palette-grey-scarlet-1, #FAF0EC)",
["Northeastern Mandarin"] = "var(--wikt-palette-grey-amber-1, #FCFAF5)",
["Jilu Mandarin"] = "var(--wikt-palette-grey-amber-1, #FCFAF5)",
["Jiaoliao Mandarin"] = "var(--wikt-palette-grey-amber-1, #FCFAF5)",
["Central Plains Mandarin"] = "var(--wikt-palette-grey-amber-1, #FCFAF5)",
["Lanyin Mandarin"] = "var(--wikt-palette-grey-amber-1, #FCFAF5)",
["Southwestern Mandarin"] = "var(--wikt-palette-grey-amber-1, #FCFAF5)",
["Jianghuai Mandarin"] = "var(--wikt-palette-grey-amber-1, #FCFAF5)",
["Mandarin"] = "var(--wikt-palette-grey-amber-1, #FCFAF5)",
["Cantonese"] = "var(--wikt-palette-grey-cyan-1, #EBF3F5)", -- doubled up with Tuhua
["Gan"] = "var(--wikt-palette-grey-teal-1, #EAF4EF)", -- doubled up with Shehua/Waxiang
["Hakka"] = "var(--wikt-palette-grey-red-1, #FBEFF0)",
["Huizhou"] = "var(--wikt-palette-grey-yellow-1, #FCFAF5)",
["Jin"] = "var(--wikt-palette-grey-orange-1, #F9F0E8)",
["Jiuxing Yumin"] = "var(--wikt-palette-grey-magenta-1, #F7EFFA)",
["Northern Min"] = "var(--wikt-palette-grey-green-1, #EDF4EA)",
["Eastern Min"] = "var(--wikt-palette-grey-green-1, #EDF4EA)",
["Southern Min"] = "var(--wikt-palette-grey-green-1, #EDF4EA)",
["Puxian Min"] = "var(--wikt-palette-grey-green-1, #EDF4EA)",
["Central Min"] = "var(--wikt-palette-grey-green-1, #EDF4EA)",
["Shaojiang Min"] = "var(--wikt-palette-grey-green-1, #EDF4EA)",
["Zhongshan Min"] = "var(--wikt-palette-grey-green-1, #EDF4EA)",
["Southern Pinghua"] = "var(--wikt-palette-grey-indigo-1, #F1F1FB)",
["Northern Pinghua"] = "var(--wikt-palette-grey-indigo-1, #F1F1FB)",
["Shehua"] = "var(--wikt-palette-grey-teal-1, #EAF4EF)", -- doubled up with Gan
["Waxiang"] = "var(--wikt-palette-grey-teal-1, #EAF4EF)",
["Wu"] = "var(--wikt-palette-grey-purple-1, #F5F0FC)",
["Xiang"] = "var(--wikt-palette-grey-blue-1, #ECF2FC)",
["Xiangnan Tuhua"] = "var(--wikt-palette-grey-cyan-1, #EBF3F5)", -- doubled up with Cantonese
["Yuebei Tuhua"] = "var(--wikt-palette-grey-cyan-1, #EBF3F5)",
}
export.special_note = {
["Classical"] = "[[w:ภาษาจีนคลาสสิก|คลาสสิก]]",
["Formal"] = "ทางการ <small>([[w:Written vernacular Chinese|Written Standard Chinese]])</small>",
["Taxonomic"] = "ชื่ออนุกรมวิธาน",
}
function export.main(frame)
local data = {}
local args = frame:getParent().args
local pagename = mw.loadData("Module:headword/data").pagename
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 = lang_obj["zh"], tr = "-" } )
local syn_table = { [=[
<div class="NavFrame" data-toggle-category="dialectal synonyms" style="border:0; max-width: 40em; text-align:center;">
<div class="NavHead" style="font-size:105%; border:1px solid var(--border-color-base, #a2a9b1); background-color: var(--wikt-palette-indigo-2, #e0defa); color:inherit; text-align:center; margin:0;">คำพ้องความในภาษาถิ่นของ ]=] ..
main_title .. ' (“' .. m_syndata["meaning"] .. '”) ' ..
"[[Template:zh-dial-map/" .. target_page .. '|<small>[แผนที่]</small>]]\n' .. [=[</div>
<div class="NavContent" style="border-top:0">
{| class="wikitable" style="margin:0; text-align:center; width: 100%; border-top: 0"
|-
! style="background:var(--wikt-palette-indigo-2, #e0defa); color:inherit; border-top:0" | วิธภาษา
! style="background:var(--wikt-palette-indigo-2, #e0defa); color:inherit; border-top:0" | ที่ตั้ง
! style="background:var(--wikt-palette-indigo-2, #e0defa); color:inherit; border-top:0" | คำ]=] .. [=[
<div style="float: right; clear: right; font-size:60%"><span class="plainlinks">[]=] ..
tostring(mw.uri.fullUrl("Module:zh/data/dial-syn/" .. target_page, { ["action"] = "edit" })) ..
' แก้ไข]</span></div>' }
local note = m_syndata["note"]
if m_syndata["Formal"][1] == "" then
m_syndata["Formal"] = { target_page }
elseif m_syndata["Formal"][1] == "-" then
m_syndata["Formal"] = nil
end
local m_dialdata = require("Module: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(export.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
if mw.title.getCurrentTitle().namespace == 828 then
require('Module:debug/track')("zh-dial-syn/" .. loc.key)
end
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("(%(.*%))", "<small>%1</small>")
location_link = loc.link or loc.key
formatted_synonyms = {}
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 lang_code = "zh"
if loc.altcode then
local alt_lang = lang_obj[loc.altcode]
local script = alt_lang:findBestScript(syn):getCode()
if script ~= "Hani" and script ~= "Hans" and script ~= "Hant" then
lang_code = loc.altcode
end
end
local synonym_link = m_links.full_link( {
term = syn .. (etym and string.format("#รากศัพท์ %s", etym) or "") .. "//",
alt = etym and (syn .. string.format("<sub>%s</sub>", etym)) .. "//",
lang = lang_obj[lang_code],
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 = export.variety_colour[variety]
table.insert(syn_table, "\n!rowspan=" .. variety_count[variety] .. (export.special_note[variety] and " colspan=2" or "") ..
' style="background:' .. colour .. '; color:inherit"| ' .. (export.special_note[variety] or export.variety_list_th[variety] or variety))
end
table.insert(syn_table,
((location_name and not export.special_note[variety]) and ('\n|style="background:' .. colour .. '; color:inherit"| ' ..
'[[w:' .. location_link .. '|' .. location_name .. ']]') or '') ..
'\n|style="background:' .. colour .. '; color:inherit"| ' ..
table.concat(formatted_synonyms, ", "))
end
end
if note and note ~= "" then
table.insert(syn_table, '\n|-\n! style="padding-top:5px; padding-bottom: 5px" | ' ..
"<small>หมายเหตุ</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