Jump to content

Module:family tree/documentation functions

From Wiktionary, the free dictionary
local export = {}

function export.etymology_language_data(frame)
	local Array = require "Module:array"
	local output = Array()
	local etymology_languages = require "Module:family tree/etymology languages"
	
	local function sort_etymology_language_codes(code1, code2)
		return etymology_languages[code1][1] < etymology_languages[code2][1]
	end
	
	for code, data in require "Module:table".sortedPairs(etymology_languages, sort_etymology_language_codes) do
		local code_list = data.codes
		if code_list[2] then
			table.sort(code_list)
			output:insert("* " .. data[1] .. " (<code>" .. code .. "</code>): "
				.. Array(code_list)
					:filter(function(alt_code)
							return alt_code ~= code
						end)
					:map(function(alt_code)
							return "<code>" .. alt_code .. "</code>"
						end)
					:concat(", "))
		end
	end
	
	return output:concat("\n")
end

return export