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 = {
= "FAF0F2",
= "FAF0F2",
= "FAF0F2",
= "FAF5F0",
= "FAF5F0",
= "FAF5F0",
= "FAF5F0",
= "FAF5F0",
= "FAF5F0",
= "FAF5F0",
= "FAF5F0",
= "F0F5FA",
= "F0FAF3",
= "FAF0F6",
= "FAF9F0",
= "FAF5F0",
= "FAF0FE",
= "F7FAF0",
= "F7FAF0",
= "F7FAF0",
= "F7FAF0",
= "F7FAF0",
= "F7FAF0",
= "F7FAF0",
= "F0F5FA",
= "F0F5FA",
= "FAF0F6",
= "F0FAF6",
= "F4F0FA",
= "F0F2FA",
= "F0F9FA",
= "F0F9FA",
}
local special_note = {
= "]",
= "Formal <small>(])</small>",
= "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 ] ]=] ..
[=[</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
! style="background:#E8ECFA" | altcode
! style="background:#E8ECFA" | GeoHack URL ]=]}
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 "]" or "]"
name = lang.english or string.format("''%s''", code)
local chinese = lang.chinese
local lat = lang.lat
local long = lang.long
local remark = ""
local altcode = ""
local url = ""
data_size = data_size + 1
if seen then
table.insert(evil, string.format('duplicated code: %s', code))
do break end
end
seen = 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
url = ""
else
chinese = 'N/A'
end
if not template then
template = {}
end
if string.find(content, '"'..code:gsub("%-", "%%-")..'", *--ubao') then
remark = "Yubao"
end
if lang.altcode then
altcode = "<code>" .. lang.altcode .. "</code>"
end
table.insert(template, {name, chinese, code, link, remark, altcode, url})
until true
end
for _, group in ipairs(variety_list) do
local colour = variety_colour
if not template then template = {} end
-- table.sort(template, function(first, second) return first < second end)
for i, point in ipairs(template) 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 ..
' style="background:#' .. colour .. '"| ' .. (special_note 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 || style="background:#%s" | %s || style="background:#%s" | %s \n',
colour, point, colour, point, colour, point, colour, point, colour, point, colour, point, colour, point))
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 ] .. tostring(count - data_size) .. ]
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