Jump to content

Module:Wikt-lang/comparison

From Wikipedia, the free encyclopedia

require('strict')
local p = {}

local function get_test_patterns(main)
	local data = require('Module:Wikt-lang/data/sandbox')
	local language_codes = {}

	if main then
		for code, values in pairs(data["languages"]) do
			table.insert(language_codes, {code, values.Wiktionary_name})
		end
	end

	local function comp(a, b)
		return a[1] < b[1]
	end

	table.sort(language_codes, comp)
	return language_codes
end

function p.main(frame)
	local wiktionary_test_patterns = get_test_patterns(true)
	local name_from_tag = require('Module:Lang')._name_from_tag
	
	local wikitable = {}
	local header = '{|class="wikitable"\n|+\n! Language code\n! Wikitionary name\n! English Wikipedia name\n|-\n'
	table.insert(wikitable, header)
	local row = '! scope="row" | %s\n | %s\n | %s\n|-\n'
	for i = 1, #wiktionary_test_patterns do
		local code = wiktionary_test_patterns[i][1]
		local wiktionary_name = wiktionary_test_patterns[i][2]
		local en_wiki_name = name_from_tag({code})
		if wiktionary_name then
			table.insert(wikitable, string.format(row, code, wiktionary_name, en_wiki_name))
		end
	end
	table.insert(wikitable, "|}")
	return table.concat(wikitable)
end

return p