Jump to content

Module:User:Trappist the monk/Name in various languages

From Wikipedia, the free encyclopedia

local get_args = require ('Module:Arguments').getArgs;
local lang_mod = require('Module:Lang')


--[[--------------------------< M A I N >----------------------------------------------------------------------
]]

local function main (frame)
	local args_t = get_args (frame);
	local raw_rows_t = {};

	local width = table.concat ({'width:', args_t.width or '100%', ';'});
	local font_size = table.concat ({'font-size:', args_t.font_size or '88%', ';'});
	local name = args_t.name;

	for tag, param_value in pairs (args_t) do
		if lang_mod._is_ietf_tag (tag) then										-- if tag is a valid language tag
			local language_link = lang_mod._name_from_tag ({tag, ['link'] = 'yes'});
			local official_name = lang_mod._lang ({tag, param_value});

			table.insert (raw_rows_t, table.concat ({							-- build a basic row
				'| style=\"padding-left:0.5em\" | ',							-- indent style same for each row
				language_link,													-- language link in the 'language column'
				': || ',														-- column separator
				official_name,													-- offical name in the official name column
				})
			);
		end
	end
	
	table.sort (raw_rows_t);													-- ascending sort because pairs() doesn't obey template parameter order
	
	local output_t = {};														-- final output collected here
	local header_t = {};														-- wikitable header stuff collected here
	
	table.insert (header_t, '{| class="mw-collapsible mw-collapsed"');			-- open wikitable as collapsed
	table.insert (header_t, 'style="');											-- begin table styling
	table.insert (header_t, width);												-- set width
	table.insert (header_t, font_size);											-- set font_size
	table.insert (header_t, 'text-align:left; border-collapse:collapse;"');		-- finish table styling

	table.insert (output_t, table.concat (header_t));							-- concatenate into a big string and save
	
	if name then
		table.insert (output_t, table.concat ({									-- build a 2-column header; shouldn't this properly be a caption for accessibility?
			'! colspan=2 style="text-align:center; border-top: 0px;" | ',		-- styling
			name,																-- and name
			'\n|- style="border-bottom:1px solid #aaa"'							-- add a bottom boarder
		}));
	end

	table.insert (output_t, table.concat (raw_rows_t, '\n|- style="border-bottom:1px solid #aaa"\n'));	-- make a big string of row data
	table.insert (output_t, '|}');												-- close the wikitable
	
	return table.concat (output_t, '\n');										-- make a damn big string and done
end


--[[--------------------------< E X P O R T E D   F U N C T I O N S >------------------------------------------
]]

return {
	main = main
	}