Module:User:Wpi/zh-dial-list
Appearance
- This module sandbox lacks a documentation subpage. Please create it.
- Useful links: root page • root page’s subpages • links • transclusions • testcases • sandbox
local export = {}
local 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"
}
local variety_colour = {
["Classical"] = "FAF0F2",
["Formal"] = "FAF0F2",
["Taxonomic"] = "FAF0F2",
["Northeastern Mandarin"] = "FAF5F0",
["Jilu Mandarin"] = "FAF5F0",
["Jiaoliao Mandarin"] = "FAF5F0",
["Central Plains Mandarin"] = "FAF5F0",
["Lanyin Mandarin"] = "FAF5F0",
["Southwestern Mandarin"] = "FAF5F0",
["Jianghuai Mandarin"] = "FAF5F0",
["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",
["Xiangnan Tuhua"] = "F0F9FA",
["Yuebei Tuhua"] = "F0F9FA",
}
local special_note = {
["Classical"] = "[[w:Classical Chinese|Classical Chinese]]",
["Formal"] = "Formal <small>([[w:Written vernacular Chinese|Written Standard Chinese]])</small>",
["Taxonomic"] = "Taxonomic name",
}
local function has_value(t, v)
for a, b in ipairs(t) do
if b == v then
return true
end
end
return false
end
function export.make_table(frame)
local variety_data = mw.loadData("Module:zh/data/dial")
local dial_table = { [=[
<div class="NavFrame" style="border:0px; max-width: 70em; 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">Readable list of [[Module:zh/data/dial]] ]=] ..
[=[</div><div class="NavContent">
{| class="wikitable" style="margin:0; text-align:center; width: 100%"
|-
! style="background:#E8ECFA" | Group
! style="background:#E8ECFA" | English
! style="background:#E8ECFA" | Chinese
! style="background:#E8ECFA" | Code
! style="background:#E8ECFA" | Link
! style="background:#E8ECFA" | Remark]=]}
local template = {}
local evil = {}
local data_size = 0
local seen = {}
content = mw.title.new('Module:zh/data/dial'):getContent()
for _, lang in ipairs(variety_data) do
repeat
local code = lang.key
local group = lang.group
local name = lang.english or code
local link = lang.link and "[[w:" .. lang.link .. "|" .. lang.link .. "]]" or "[[w:" .. name .. "|''" .. name .. "'']]"
name = lang.english or string.format("''%s''", code)
local chinese = lang.chinese
local lat = lang.lat
local long = lang.long
local remark = ""
data_size = data_size + 1
if seen[code] then
table.insert(evil, string.format('duplicated code: %s', code))
do break end
end
seen[code] = true
if not group then
table.insert(evil, string.format('%s has no value for group', code))
group = "Missing"
end
if not has_value(variety_list, group) then
table.insert(evil, string.format('"%s" is not a valid group', group))
do break end
end
if not (group == 'Taxonomic' or group == 'Classical' or group == 'Formal') then
if not chinese then
table.insert(evil, string.format('%s has no value for <code>chinese</code>', code))
do break end
end
if not lat then
table.insert(evil, string.format('%s has no value for <code>lat</code>', code))
end
if not long then
table.insert(evil, string.format('%s has no value for <code>long</code>', code))
end
else
chinese = 'N/A'
end
if not template[group] then
template[group] = {}
end
if string.find(content, '"'..code..'", *--yubao.+') then
remark = "Yubao"
end
table.insert(template[group], {name, chinese, code, link, remark})
until true
end
for _, group in ipairs(variety_list) do
local colour = variety_colour[group]
if not template[group] then template[group] = {} end
-- table.sort(template[group], function(first, second) return first[1] < second[1] end)
for i, point in ipairs(template[group]) do
repeat
table.insert(dial_table, '\n|-')
if not point then
do break end
elseif i == 1 then
table.insert(dial_table, "\n!rowspan=" .. #template[group] ..
' style="background:#' .. colour .. '"| ' .. (special_note[group] or group))
end
table.insert(dial_table, string.format('\n| style="background:#%s" | %s || style="background:#%s" | %s || style="background:#%s" | <code>%s</code> || style="background:#%s" | %s || style="background:#%s" | %s \n',
colour, point[1], colour, point[2], colour, point[3], colour, point[4], colour, point[5]))
until true
end
end
local _, count = content:gsub('\nvariety_data', '')
count = count - 1 -- L1: local variety_data = {}
local size_text = (count == data_size) and 'Number of entries: ' .. tostring(data_size) or [[<span style="color:red"><b> There are ]] .. tostring(count - data_size) .. [[ pairs of entries with duplicate codes</b></span>]]
local size_text = 'Number of entries: ' .. tostring(data_size)
table.insert(dial_table, '\n|}</div></div>')
table.insert(dial_table, [[
===Notes===
* ''italic'' indicates value is not manually set and was defaulted to other values.
===Errors===
Please note that only one error is catched per entry. Preview again until no errors are found.
<div style="color:red"><b>]] .. table.concat(evil, '\n\n') .. [[</b></div>
]] .. size_text)
return table.concat(dial_table, '')
end
--TODO: add coords
return export