Modul:languages/print

Ji Wîkîferheng
Jump to navigation Jump to search
Template-info.png Belgekirina modulê[nîşan bide] [biguherîne] [rojane bike]
Ev belge ji Modul:languages/print/belge hatiye girtin.

Ji bo rojanekirina Modul:ziman/ji kod li nav vê kodê veşartî bi kar bîne:

Ji bo rojanekirina Modul:ziman/navên zimanan vê kodê veşartî bi kar bîne:

local export = {}

local function generate_table(name_to_code)
	local result = {}
	
	local iterate
	if name_to_code then
		function iterate(module)
			for code, data in pairs(mw.loadData("Modul:ziman/" .. module)) do
				result[data[1]] = code
			end
		end
	else
		function iterate(module)
			for code, data in pairs(mw.loadData("Modul:ziman/" .. module)) do
				result[code] = data[1]
			end
		end
	end
	
	iterate("dane2")
	
	for letter in string.gmatch("abcdefghijklmnopqrstuvwxyz", ".") do
		iterate("dane3/" .. letter)
	end
	
	iterate("danex")
	
	return result
end

local function dump(data, name_to_code)
	local output = { "return {" }
	local i = 1
	local sorted_pairs = require "Module:table".sortedPairs
	
	for k, v in sorted_pairs(data) do
		i = i + 1
		output[i] = ('\t[%q] = %q,'):format(k, v)
	end
	
	table.insert(output, "}")
	
	return table.concat(output, "\n")
end

local function print_data(name_to_code, args)
	if args[1] == "plain" then
		return dump(generate_table(name_to_code), name_to_code)
	else
		return require "Module:debug".highlight(dump(generate_table(name_to_code), name_to_code))
	end
end

function export.code_to_name(frame)
	return print_data(false, frame.args)
end

function export.name_to_code(frame)
	return print_data(true, frame.args)
end

return export