Module:User:Wpi/zh-dial-list

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"] = "Classical Chinese", ["Formal"] = "Formal (Written Standard Chinese) ", ["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 = { [=[ Readable list of Module:zh/data/dial ]=] .. [=[ 	{| 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]=]} local template = {} local evil = {} local data_size = 0 --	local order_check = {} local seen = {} for _, lang in ipairs(variety_data) do		repeat local code = lang.key local group = lang.group --			local order = lang.order local name = lang.english or code local link = lang.link and "" .. lang.link .. "" or "" .. name .. "" name = lang.english or string.format("%s", code) local chinese = lang.chinese local lat = lang.lat local long = lang.long 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 order then --				table.insert(evil, string.format('%s has no value for ', code)) --				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)) do break end end if not lat then table.insert(evil, string.format('%s has no value for ', code)) end if not long then table.insert(evil, string.format('%s has no value for ', code)) end else chinese = 'N/A' end if not template[group] then template[group] = {} end --			if not order_check[group] then --				order_check[group] = {} --			end --			if order_check[group][order] then --				table.insert(evil, string.format(order_check[group][order] .. ' and ' .. code .. ' share the same order number')) --				do break end --			else --				order_check[group][order] = code --			end --			table.insert(template[group], {order, name, chinese, code, link}) table.insert(template[group], {name, chinese, code, link}) 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" |  || style="background:#%s" | %s \n', colour, point[1], colour, point[2], colour, point[3], colour, point[4])) until true end end --	content = mw.title.new('Module:zh/data/dial'):getContent --	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 ''' There are  .. tostring(count - data_size) .. pairs of entries with duplicate codes''' local size_text = 'Number of entries: ' .. tostring(data_size) table.insert(dial_table, '\n|} ') table.insert(dial_table, [[

Errors
Please note that only one error is catched per entry. Preview again until no errors are found. ''']] .. table.concat(evil, '\n\n') .. ' .. size_text)	return table.concat(dial_table, ) end

--TODO: add coords return export