Jump to content

Module:Mandarin frequency list

From Wiktionary, the free dictionary

Used to quickly generate tables of words in subpages of Appendix:Mandarin Frequency lists.


local export = {}
	
local header = [[
{| class="wikitable"
|-
! Traditional !! Simplified !! Pinyin !! Meaning
]]
local footer = [[|}]]

local function link(word, lang_code, lang_name, script)
	return '<span class="' .. script .. '" lang="' .. lang_code .. '">[['
		.. word .. '#' .. lang_name .. '|' .. word .. ']]</span>'
end

function export.list(frame)
	local args = require "Module:table".shallowcopy(frame.args)
	if #args % 4 ~= 0 then
		error(("The number of arguments should be a multiple of four, but is %d")
			:format(#args))
	end
	
	local Array = require "Module:array"
	local output = Array()
	output:insert(header)
	for i = 1, #args, 4 do
		local traditional, simplified, pinyin, gloss = unpack(args, i, i + 3)
		output:insert(("|-\n| %s || %s || %s || %s\n"):format(
			link(traditional, "zh-Hant", "Chinese", "Hant"),
			link(simplified, "zh-Hans", "Chinese", "Hans"),
			link(pinyin, "cmn-Latn-pinyin", "Mandarin", "Latn"),
			gloss))
	end
	output:insert(footer)
	return output:concat()
end

return export