Jump to content
Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 20:46, 1 June 2026 by Gravy (talk | contribs) (done)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Infobox country/doc

require('strict')

local p = {}

local function isNonEmpty( value )
	return value ~= nil and tostring( value ) ~= ''
end

local function makeImages( args )
	local images = {}

	if isNonEmpty( args.image_flag ) then
		table.insert( images, {
			label = 'Flag',
			src = args.image_flag,
		} )
	end

	if isNonEmpty( args.image_symbol ) then
		table.insert( images, {
			label = args.symbol_type or "Symbol",
			src = args.image_symbol,
		} )
	end

	if #images > 0 then
		return images
	end

	return nil
end

local function makeLeaders( args )
	local leaders = {}
	
	local i = 1

	while isNonEmpty( args[ 'leader_title' .. i ] ) and isNonEmpty( args[ 'leader_name' .. i ] ) do
		table.insert( leaders, {
			label = args[ 'leader_title' .. i ],
			content = args[ 'leader_name' .. i ],
		} )

		i = i + 1
	end
	
	if #leaders > 0 then
		return leaders
	end

	return nil
end

local function makeEvents( args )
	local events = {}
	
	local i = 1

	while isNonEmpty( args[ 'established_event' .. i ] ) and isNonEmpty( args[ 'established_date' .. i ] ) do
		table.insert( events, {
			label = args[ 'established_event' .. i ],
			content = args[ 'established_date' .. i ],
		} )

		i = i + 1
	end
	
	if #events > 0 then
		return events
	end

	return nil
end

function p.main( frame )
    local infobox = require( 'Module:InfoboxLua' )
    local args = require( 'Module:Arguments' ).getArgs( frame )
    
    local leaders = makeLeaders( args )
    local events = makeEvents( args )
    
    local data = {
        title = args.conventional_long_name or mw.title.getCurrentTitle().text,
        subtitle = args.common_name,
        images = makeImages( args ),
        sections = {
            {
                items = {
                	{ label = args.capital == args.largest_city and 'Capital<br>(and largest city)' or 'Capital', content = args.capital },
                	args.capital ~= args.largest_city and { label = args.largest_settlement_type or 'Largest city', content = args.largest_city } or nil,
                    { label = args.admin_center_type or 'Administrative center', content = args.admin_center },
                    { label = args.languages_type or 'Official languages', content = args.languages },
                    { label = 'Type', content = args.org_type },
                    { label = args.membership_type or 'Membership', content = args.membership },
                }
            },
            leaders and {
            	label = "Government",
            	columns = 2,
            	items = leaders
            } or nil,
            events and {
            	label = "Establishment",
            	items = events
            } or nil
        }
    }
    
    return infobox.render( data )
end

return p
Last modified