Jump to content

Module:Infobox country

Unchecked
From Wikipedia

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

--require "mw.text"
--require "mw.page"

local z = {}
local wikitext = require "Module:wikitext"
local infobox = require "Module:infobox"
local coordinates = require "Module:coordinates"

local iso3166map = {}
iso3166map["Andorra"] = "AD"
iso3166map["United Arab Emirates"] = "AE"
iso3166map["Afghanistan"] = "AF"
iso3166map["Antigua and Barbuda"] = "AG"
iso3166map["Anguilla"] = "AI"
iso3166map["Albania"] = "AL"
iso3166map["Armenia"] = "AM"
iso3166map["Angola"] = "AO"
iso3166map["Antarctica"] = "AQ"
iso3166map["Argentina"] = "AR"
iso3166map["American Samoa"] = "AS"
iso3166map["Austria"] = "AT"
iso3166map["Australia"] = "AU"
iso3166map["Aruba"] = "AW"
iso3166map["Åland Islands"] = "AX"
iso3166map["Azerbaijan"] = "AZ"
iso3166map["Bosnia and Herzegovina"] = "BA"
iso3166map["Barbados"] = "BB"
iso3166map["Bangladesh"] = "BD"
iso3166map["Belgium"] = "BE"
iso3166map["Burkina Faso"] = "BF"
iso3166map["Bulgaria"] = "BG"
iso3166map["Bahrain"] = "BH"
iso3166map["Burundi"] = "BI"
iso3166map["Benin"] = "BJ"
iso3166map["Saint Barthélemy"] = "BL"
iso3166map["Bermuda"] = "BM"
iso3166map["Brunei"] = "BN"
iso3166map["Bolivia"] = "BO"
iso3166map["Bonaire, Sint Eustatius and Saba"] = "BQ"
iso3166map["Brazil"] = "BR"
iso3166map["The Bahamas"] = "BS"
iso3166map["Bhutan"] = "BT"
iso3166map["Bouvet Island"] = "BV"
iso3166map["Botswana"] = "BW"
iso3166map["Belarus"] = "BY"
iso3166map["Belize"] = "BZ"
iso3166map["Canada"] = "CA"
iso3166map["Cocos (Keeling) Islands"] = "CC"
iso3166map["Democratic Republic of the Congo"] = "CD"
iso3166map["Central African Republic"] = "CF"
iso3166map["Republic of the Congo"] = "CG"
iso3166map["Switzerland"] = "CH"
iso3166map["Côte d'Ivoire"] = "CI"
iso3166map["Cook Islands"] = "CK"
iso3166map["Chile"] = "CL"
iso3166map["Cameroon"] = "CM"
iso3166map["China"] = "CN"
iso3166map["Colombia"] = "CO"
iso3166map["Costa Rica"] = "CR"
iso3166map["Cuba"] = "CU"
iso3166map["Cape Verde"] = "CV"
iso3166map["Curaçao"] = "CW"
iso3166map["Christmas Island"] = "CX"
iso3166map["Cyprus"] = "CY"
iso3166map["Czech Republic"] = "CZ"
iso3166map["Germany"] = "DE"
iso3166map["Djibouti"] = "DJ"
iso3166map["Denmark"] = "DK"
iso3166map["Dominica"] = "DM"
iso3166map["Dominican Republic"] = "DO"
iso3166map["Algeria"] = "DZ"
iso3166map["Ecuador"] = "EC"
iso3166map["Estonia"] = "EE"
iso3166map["Egypt"] = "EG"
iso3166map["Western Sahara"] = "EH"
iso3166map["Eritrea"] = "ER"
iso3166map["Spain"] = "ES"
iso3166map["Ethiopia"] = "ET"
iso3166map["Finland"] = "FI"
iso3166map["Fiji"] = "FJ"
iso3166map["Falkland Islands"] = "FK"
iso3166map["Federated States of Micronesia"] = "FM"
iso3166map["Faroe Islands"] = "FO"
iso3166map["France"] = "FR"
iso3166map["Gabon"] = "GA"
iso3166map["United Kingdom"] = "GB"
iso3166map["Grenada"] = "GD"
iso3166map["Georgia (country)"] = "GE"
iso3166map["French Guiana"] = "GF"
iso3166map["Guernsey"] = "GG"
iso3166map["Ghana"] = "GH"
iso3166map["Gibraltar"] = "GI"
iso3166map["Greenland"] = "GL"
iso3166map["The Gambia"] = "GM"
iso3166map["Guinea"] = "GN"
iso3166map["Guadeloupe"] = "GP"
iso3166map["Equatorial Guinea"] = "GQ"
iso3166map["Greece"] = "GR"
iso3166map["South Georgia and the South Sandwich Islands"] = "GS"
iso3166map["Guatemala"] = "GT"
iso3166map["Guam"] = "GU"
iso3166map["Guinea-Bissau"] = "GW"
iso3166map["Guyana"] = "GY"
iso3166map["Hong Kong"] = "HK"
iso3166map["Heard Island and McDonald Islands"] = "HM"
iso3166map["Honduras"] = "HN"
iso3166map["Croatia"] = "HR"
iso3166map["Haiti"] = "HT"
iso3166map["Hungary"] = "HU"
iso3166map["Indonesia"] = "ID"
iso3166map["Republic of Ireland"] = "IE"
iso3166map["Israel"] = "IL"
iso3166map["Isle of Man"] = "IM"
iso3166map["India"] = "IN"
iso3166map["British Indian Ocean Territory"] = "IO"
iso3166map["Iraq"] = "IQ"
iso3166map["Iran"] = "IR"
iso3166map["Iceland"] = "IS"
iso3166map["Italy"] = "IT"
iso3166map["Jersey"] = "JE"
iso3166map["Jamaica"] = "JM"
iso3166map["Jordan"] = "JO"
iso3166map["Japan"] = "JP"
iso3166map["Kenya"] = "KE"
iso3166map["Kyrgyzstan"] = "KG"
iso3166map["Cambodia"] = "KH"
iso3166map["Kiribati"] = "KI"
iso3166map["Comoros"] = "KM"
iso3166map["Saint Kitts and Nevis"] = "KN"
iso3166map["North Korea"] = "KP"
iso3166map["South Korea"] = "KR"
iso3166map["Kuwait"] = "KW"
iso3166map["Cayman Islands"] = "KY"
iso3166map["Kazakhstan"] = "KZ"
iso3166map["Laos"] = "LA"
iso3166map["Lebanon"] = "LB"
iso3166map["Saint Lucia"] = "LC"
iso3166map["Liechtenstein"] = "LI"
iso3166map["Sri Lanka"] = "LK"
iso3166map["Liberia"] = "LR"
iso3166map["Lesotho"] = "LS"
iso3166map["Lithuania"] = "LT"
iso3166map["Luxembourg"] = "LU"
iso3166map["Latvia"] = "LV"
iso3166map["Libya"] = "LY"
iso3166map["Morocco"] = "MA"
iso3166map["Monaco"] = "MC"
iso3166map["Moldova"] = "MD"
iso3166map["Montenegro"] = "ME"
iso3166map["Collectivity of Saint Martin"] = "MF"
iso3166map["Madagascar"] = "MG"
iso3166map["Marshall Islands"] = "MH"
iso3166map["Republic of Macedonia"] = "MK"
iso3166map["Mali"] = "ML"
iso3166map["Myanmar"] = "MM"
iso3166map["Mongolia"] = "MN"
iso3166map["Macau"] = "MO"
iso3166map["Northern Mariana Islands"] = "MP"
iso3166map["Martinique"] = "MQ"
iso3166map["Mauritania"] = "MR"
iso3166map["Montserrat"] = "MS"
iso3166map["Malta"] = "MT"
iso3166map["Mauritius"] = "MU"
iso3166map["Maldives"] = "MV"
iso3166map["Malawi"] = "MW"
iso3166map["Mexico"] = "MX"
iso3166map["Malaysia"] = "MY"
iso3166map["Mozambique"] = "MZ"
iso3166map["Namibia"] = "NA"
iso3166map["New Caledonia"] = "NC"
iso3166map["Niger"] = "NE"
iso3166map["Norfolk Island"] = "NF"
iso3166map["Nigeria"] = "NG"
iso3166map["Nicaragua"] = "NI"
iso3166map["Netherlands"] = "NL"
iso3166map["Norway"] = "NO"
iso3166map["Nepal"] = "NP"
iso3166map["Nauru"] = "NR"
iso3166map["Niue"] = "NU"
iso3166map["New Zealand"] = "NZ"
iso3166map["Oman"] = "OM"
iso3166map["Panama"] = "PA"
iso3166map["Peru"] = "PE"
iso3166map["French Polynesia"] = "PF"
iso3166map["Papua New Guinea"] = "PG"
iso3166map["Philippines"] = "PH"
iso3166map["Pakistan"] = "PK"
iso3166map["Poland"] = "PL"
iso3166map["Saint Pierre and Miquelon"] = "PM"
iso3166map["Pitcairn Islands"] = "PN"
iso3166map["Puerto Rico"] = "PR"
iso3166map["Palestinian territories"] = "PS"
iso3166map["Portugal"] = "PT"
iso3166map["Palau"] = "PW"
iso3166map["Paraguay"] = "PY"
iso3166map["Qatar"] = "QA"
iso3166map["Reunion"] = "RE"
iso3166map["Romania"] = "RO"
iso3166map["Serbia"] = "RS"
iso3166map["Russia"] = "RU"
iso3166map["Rwanda"] = "RW"
iso3166map["Saudi Arabia"] = "SA"
iso3166map["Solomon Islands"] = "SB"
iso3166map["Seychelles"] = "SC"
iso3166map["Sudan"] = "SD"
iso3166map["Sweden"] = "SE"
iso3166map["Singapore"] = "SG"
iso3166map["Saint Helena, Ascension and Tristan da Cunha"] = "SH"
iso3166map["Slovenia"] = "SI"
iso3166map["Svalbard and Jan Mayen"] = "SJ"
iso3166map["Slovakia"] = "SK"
iso3166map["Sierra Leone"] = "SL"
iso3166map["San Marino"] = "SM"
iso3166map["Senegal"] = "SN"
iso3166map["Somalia"] = "SO"
iso3166map["Suriname"] = "SR"
iso3166map["South Sudan"] = "SS"
iso3166map["São Tomé and Príncipe"] = "ST"
iso3166map["El Salvador"] = "SV"
iso3166map["Sint Maarten"] = "SX"
iso3166map["Syria"] = "SY"
iso3166map["Swaziland"] = "SZ"
iso3166map["Turks and Caicos Islands"] = "TC"
iso3166map["Chad"] = "TD"
iso3166map["French Southern and Antarctic Lands"] = "TF"
iso3166map["Togo"] = "TG"
iso3166map["Thailand"] = "TH"
iso3166map["Tajikistan"] = "TJ"
iso3166map["Tokelau"] = "TK"
iso3166map["East Timor"] = "TL"
iso3166map["Turkmenistan"] = "TM"
iso3166map["Tunisia"] = "TN"
iso3166map["Tonga"] = "TO"
iso3166map["Turkey"] = "TR"
iso3166map["Trinidad and Tobago"] = "TT"
iso3166map["Tuvalu"] = "TV"
iso3166map["Taiwan"] = "TW"
iso3166map["Tanzania"] = "TZ"
iso3166map["Ukraine"] = "UA"
iso3166map["Uganda"] = "UG"
iso3166map["United States Minor Outlying Islands"] = "UM"
iso3166map["United States"] = "US"
iso3166map["Uruguay"] = "UY"
iso3166map["Uzbekistan"] = "UZ"
iso3166map["Vatican City"] = "VA"
iso3166map["Saint Vincent and the Grenadines"] = "VC"
iso3166map["Venezuela"] = "VE"
iso3166map["British Virgin Islands"] = "VG"
iso3166map["United States Virgin Islands"] = "VI"
iso3166map["Vietnam"] = "VN"
iso3166map["Vanuatu"] = "VU"
iso3166map["Wallis and Futuna"] = "WF"
iso3166map["Samoa"] = "WS"
iso3166map["Yemen"] = "YE"
iso3166map["Mayotte"] = "YT"
iso3166map["South Africa"] = "ZA"
iso3166map["Zambia"] = "ZM"
iso3166map["Zimbabwe"] = "ZW"

local getarea = function (prefix, args)
    local area = {}
    local floor = math.floor
    local km2 = args[prefix .. "area_km2"] or args[prefix .. "areatotal"]
    local sqmi = args[prefix .. "area_sq_mi"] or args[prefix .. "areami²"]
    if nil == km2 then 
        local n = tonumber(sqmi)
        if n then
            area.km2 = floor(n * 2.589988110336)
        else
            area.km2 = nil
        end
    else 
        area.km2 = km2 
    end
    if nil == sqmi then
        local n = tonumber(km2)
        if n then
            area.sqmi = floor(n / 2.589988110336)
        else
            area.sqmi = nil
        end
    else
        area.sqmi = sqmi
    end
    local area_rank = args[prefix .. "area_rank"] or args[prefix .. "arearank"]
    if ( area_rank ) then area.rank = "([[List of countries and outlying territories by total area|" .. area_rank .. "]])" end
    area.note = args[prefix .. "area_footnote"]
    return area
end

local makeareastring = function (area)
    local text = {}
    if area.km2 then 
        table.insert(text, area.km2 .. " km<sup>2</sup>")
        if area.note then table.insert(text, area.note) area.note = nil end
        table.insert(text, " ")
    end
    if area.sqmi then 
        table.insert(text, area.sqmi .. " sq&nbsp;mi")
        if area.note then table.insert(text, area.note) area.note = nil end
        table.insert(text, " ")
    end
    if area.rank then table.insert(text, area.rank) end
    if nil == next(text) then return nil else return table.concat(text) end    
end

-- This is used by template {{infobox country}}.
function z.country(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    
    local pagename = config.pagename
    -- Should have "mw.page.title.name" instead of "pagename", but that isn't available yet.
    local country = args.common_name or args.name or args.linking_name or pagename or "country"
    local countrylink = args.linking_name or args.common_name or args.name or pagename or "country"

    local t = {}
    t.image = args.image
    t.caption = args.caption
    t.titleclass = "summary"
    t.bodyclass = "vevent"
    t.class = "infobox geography vcard"
    t.style = "width: 22em; font-size: 88%"
    local box = 1

    local names = ""
    if ( args.conventional_long_name ) then
        names = mw.text.tag({name="span", contents=args.conventional_long_name, params={class="fn org country-name"}})
    end
    if ( args.native_name or args.name ) then
        if (args.native_name) then names = names .. args.native_name end
        if (args.name) then 
            if (args.native_name) then names = names .. "<br>" end
            names = names .. mw.text.tag({name="span", contents=args.name, params={class="fn org country-name"}}) 
        end
        names = mw.text.tag({name="div", contents=names, params={style="padding-top:0.25em;"}})
    end
    t[box] = { single = true }
    t[box][1] = { label = names, data = "" }
    box = box + 1

    -- Flags and Arms box
    local flags_table = {}
    table.insert(flags_table, "\n{|\n|-\n")
    if ( args.image_flag ) then
        local caption = mw.text.tag({name="small", contents="[[" ..(args.flag_caption or ("Flag of " .. country)) .. "]]", params={}})
        caption = mw.text.tag({name="div", contents=caption, params={style="position:relative; top:0.3em;"}})
        local text = "| width=" .. (args.flag_width or "55%") .. "\"|[[File:" .. args.image_flag .. "|125px|center|alt=" .. (args.alt_flag or args.flag_caption or ("Flag of " .. country)) .. "]]" .. caption .. "\n"
        table.insert(flags_table, text)
    end
    if ( args.image_flag2 ) then
        local caption = mw.text.tag({name="small", contents="[[" ..(args.flag2_caption or ("Flag of " .. country)) .. "]]", params={}})
        caption = mw.text.tag({name="div", contents=caption, params={style="position:relative; top:0.3em;"}})
        local text = "| width=\"" .. (args.flag2_width or "45%") .. "\"|[[File:" .. args.image_flag2 .. "|125px|center|alt=" .. (args.alt_flag2 or args.flag2_caption or ("Flag of " .. country)) .. "]]" .. caption .. "\n"
        table.insert(flags_table, text)
    end
    if ( args.image_coat ) then
        local caption = mw.text.tag({name="small", contents="[[" ..(args.coat_caption or ((args.symbol_type or "Coat of arms") .. " of " .. country)) .. "]]", params={}})
        caption = mw.text.tag({name="div", contents=caption, params={style="position:relative; top:0.3em;"}})
        local text = "| width=\"" .. (args.coat_width or "45%") .. "\"|[[File:" .. args.image_coat .. "|85px|center|alt=" .. (args.alt_coat or args.coat_caption or ("Coat of arms of " .. country)) .. "]]" .. caption .. "\n"
        table.insert(flags_table, text)
    end
    table.insert(flags_table, "|}")
    t[box] = { single = true }
    t[box][1] = { raw = table.concat(flags_table) }
    box = box + 1

    -- Mottoes box
    t[box] = { single = true }
    t[box][1] = { label = "Motto", data = (args.national_motto or args.nationalmotto or "") .. (args.motto or "") }
    box = box + 1
    
    -- Anthems and songs box
    t[box] = { single = true }
    t[box][1] = { label = "Anthem", data = args.national_anthem or args.anthem or args.nationalsong }
    t[box][2] = { label = "[[Royal anthem]]", data = args.royal_anthem }
    box = box + 1
    
    -- Symbols box
    t[box] = { single = true }
    t[box][1] = { label = args.other_symbol_type, data = args.other_symbol }
    t[box][2] = { label = args.text_symbol_type, data = args.text_symbol }
    box = box + 1
    
    -- Two maps
    local image_map1
    if ( args.image_map ) then
        local caption = mw.text.tag({name="small", contents=(args.map_caption or ""), params={}})
        caption = mw.text.tag({name="div", contents=caption, params={style="position:relative; top:0.3em;"}})
        image_map1 = "[[File:" .. args.image_map .. "|" .. (args.map_width or "280px") .. "|center|alt=" .. (args.alt_map or args.map_caption or ("Location of " .. country)) .. "]]" .. caption
    end
    local image_map2
    if ( args.image_map2 ) then
        local caption = mw.text.tag({name="small", contents=(args.map_caption2 or ""), params={}})
        caption = mw.text.tag({name="div", contents=caption, params={style="position:relative; top:0.3em;"}})
        image_map2 = "[[File:" .. args.image_map2 .. "|" .. (args.map2_width or "280px") .. "|center|alt=" .. (args.alt_map2 or args.map_caption2 or ("Location of " .. country)) .. "]]" .. caption
    end
    t[box] = { single = true }
    t[box][1] = { image = image_map1 }
    t[box][2] = { image = image_map2 }
    box = box + 1

    -- Capital and centre box
    local capital = args.capital
    if capital then
        local coord_args = {
            args.latd or "",
            args.latm or "",
            args.lats or "0",
            args.latNS or "",
            args.longd or "",
            args.longm or "",
            args.longs or "0",
            args.longEW or ""
        }
        local coord_config = {}
        local coord_pframe = {
            preprocess = function (self, s) return pframe:preprocess(s) end,
            argumentPairs = function (self) return pairs(self.args) end,
            args = coord_args
        }
        local coord_frame = {
            getParent = function (self) return coord_pframe end,
            preprocess = function (self, s) return frame:preprocess(s) end,
            argumentPairs = function (self) return pairs(self.args) end,
            args = coord_config
        }
        local capital_coordinates = coordinates.coord(coord_frame)
        capital = capital .. capital_coordinates
    end
    local and_largest
    local largest_city = args.largest_city
    if largest_city == "capital" or largest_city == "\"capital\"" or largest_city == "[[capital]]" then
        largest_city = nil
        and_largest = " (and largest city)"
    else
        and_largest = ""
    end
    local largest_settlement = args.largest_settlement
    if largest_settlement == "capital" or largest_settlement == "\"capital\"" or largest_settlement == "[[capital]]" then
        largest_settlement = nil
    end    
    t[box] = { single = false }
    t[box][1] = { label = "Capital" .. and_largest, data = capital }
    t[box][2] = { label = "Largest city", data = largest_city }
    t[box][3] = { label = "Largest " .. (args.largest_settlement_type or ""), data = largest_settlement }
    t[box][4] = { label = args.admin_centre_type or args.admin_center_type or "Administrative center", data = args.admin_centre or args.admin_center  }
    box = box + 1
    
    -- Languages boxes
    local ethnic_groups = args.ethnic_groups
    if ( ethnic_groups ) then
        local ethnic_groups_year = args.ethnic_groups_year
        if ethnic_groups_year then ethnic_groups_year = " (" .. ethnic_groups_year .. ")" else ethnic_groups_year = "" end
        ethnic_groups = ethnic_groups .. ethnic_groups_year
    else
        ethnic_groups = nil
    end
    t[box] = { single = false }
    t[box][1] = { label = "Official language(s)", data = args.official_languages or args.officiallanguages }
    t[box][2] = { label = "Recognized national&nbsp;languages", data = args.national_languages }
    t[box][3] = { label = "Recognized regional&nbsp;languages", data = args.regional_languages }
    t[box][4] = { label = "Ethnic group(s)", data = ethnic_groups }
    box = box + 1
    t[box] = { single = false }
    t[box][1] = { label = "[[National language]](s)", data = args.languages }
    box = box + 1
    
    -- Politics box
    local government_type = args.government_type
    if ( government_type ) then
        local politics_link = args.politics_link or ("Politics of " .. country)
        local government = "[[" .. politics_link .. "|Government]]" 
        t[box] = { single = false }
        t[box][1] = { label = government, data = government_type }
    else
        local government
        if ( args.membership ) then government = "Leaders" else government = "Government" end
        t[box] = { single = true }
        t[box][1] = { label = government, data = "" }
    end
    for i=1,9,1 do
        t[box][i + 1] = { label = args["leader_title" .. i], data = args["leader_name" .. i] }
    end
    box = box + 1
    
    -- Establishment box
    t[box] = { single = false }
    local sovereignty_type = args.sovereignty_type
    if ( sovereignty_type ) then
        local sovereignty_note = args.sovereignty_note
        if ( sovereignty_note ) then
            t[box][1] = { label = sovereignty_type, data = sovereignty_note }
        else
            t[box][1] = { label = sovereignty_type, data = "" }
        end
    else
        local established = args.established or args.establishedin
        if ( established ) then
            t[box][1] = { label = "Established", data = established }
        else
            t[box][1] = { label = "Establishment", data = "" }
        end
    end
    for i=1,15,1 do
        t[box][i + 1] = { label = args["established_event" .. i], data = args["established_date" .. i] }
    end
    box = box + 1
    
    -- Demonyns box
    t[box] = { single = false }
    t[box][1] = { label = "[[Demonym]]", data = args.demonym }
    box = box + 1
    
    -- Membership box
    t[box] = { single = false }
    t[box][1] = { label = "Type", data = args.org_type }
    t[box][2] = { label = args.membership_type or "Membership", data = args.membership }
    box = box + 1
    
    -- Type box
    t[box] = { single = false }
    t[box][2] = { label = "Type", data = args.org_type }
    box = box + 1
    
    -- Legislature box
    t[box] = { single = false }
    t[box][1] = { label = "Legislature", data = args.legislature }
    t[box][2] = { label = "[[Upper house]]", data = args.upper_house }
    t[box][3] = { label = "[[Lower house]]", data = args.lower_house }
    box = box + 1
    
    -- Area box
    local area_link = args.area_link or ("Geography of " .. country)
    local area_title = "[[" .. area_link .. "|Area]]"
    local area_label = (args.area_label or "Total") .. (args.FR_foot4 or "")
    local area = getarea("", args)
    local FR_IGN_area = getarea("FR_IGN_", args)
    local FR_cadastre_area = getarea("FR_cadastre_", args)
    local area_data2 = args.area_data2
    if area_data2 ~= nil then
        area_data2 = area_data2 .. (args.area_dabodyalign or "")
    end
    t[box] = { single = false }
    t[box][1] = { label = area_title, data = "" }
    t[box][2] = { label = area_label, data = makeareastring(area) }
    t[box][3] = { label = "Water&nbsp;(%)", data = args.percent_water or args.areawaterpercent }
    t[box][4] = { label = args.area_label2 or "", data = area_data2 }
    t[box][5] = { label = args.FR_metropole, data = "" }
    t[box][6] = { label = "[[Institut Géographique National|IGN]]" .. (args.FR_foot2 or ""), data = makeareastring(FR_IGN_area) }
    t[box][7] = { label = "[[Cadastre]]" .. (args.FR_foot3 or ""), data = makeareastring(FR_cadastre_area) }
    box = box + 1
    
    -- Population box
    local population_estimate = args.population_estimate
    local population_estimate_label = args.population_estimate_year
    if ( population_estimate_label ) then population_estimate_label = population_estimate_label .. " estimate" else population_estimate_label = "Estimate" end
    local population_census_label = args.population_census_year
    if ( population_census_label ) then population_census_label = population_census_label .. " census" else population_census_label = "Census" end
    if ( population_estimate ) then
        local rank = args.population_estimate_rank
        if ( rank ) then rank = " ([[List of countries by population|" .. rank .. "]])" else rank = "" end
        population_estimate = population_estimate .. rank
    end
    local population_census = args.population_census or args.populationtotal
    if ( population_census ) then
        local rank = args.population_census_rank or args.populationrank
        if ( rank ) then rank = " ([[List of countries by population|" .. rank .. "]])" else rank = "" end
        population_census = population_census .. rank
    end
    local population_label = args.population_link
    if ( nil == population_label ) then
        population_label = "Demographics of " .. country
    end
    if ( population_label ) then population_label = "[[" .. population_label .. "|Population]]" else population_label = "" end
    local population_density = ""
    if (args.population_density_km2) then
        population_density = population_density .. args.population_density_km2 .. " per km<sup>2</sup>"
    elseif (args.population_density_sq_mi) then
        population_density = population_density .. args.population_density_sq_mi .. " per sq&nbsp;mi"
    elseif (args["population_density_mi²"]) then
        population_density = population_density .. args["population_density_mi²"] .. " per mi<sup>2</sup>"
    elseif (args.populationdensity) then
        population_density = population_density .. args.populationdensity  .. " per km<sup>2</sup>"
    end
    if (population_density) then 
        local footnote = args.pop_den_footnote or ""
        local rank = args.population_density_rank
        if ( rank ) then rank = " ([[List of sovereign states and dependent territories by population density|" .. rank .. "]])" else rank = "" end
        population_density = population_density .. footnote .. rank
    end
    local FR_total_population_estimate = args.FR_total_population_estimate
    if (FR_total_population_estimate) then
        local rank = args.FR_total_population_estimate_rank
        if (rank) then rank = " ([[List of countries by population in 2005|" .. rank .. "]])" else rank = "" end
        FR_total_population_estimate = FR_total_population_estimate .. rank
    end
    local FR_metropole_population_estimate = args.FR_metropole_population
    if (FR_metropole_population_estimate) then
        local rank = args.FR_metropole_population_estimate_rank
        if (rank) then rank = " ([[List of countries by population in 2005|" .. rank .. "]])" else rank = "" end
        FR_metropole_population_estimate = FR_metropole_population_estimate .. rank
    end
    t[box] = { single = false }
    t[box][1] = { label = population_label, data = "" }
    t[box][2] = { label = population_estimate_label, data = population_estimate }
    t[box][3] = { label = population_census_label, data = population_census }
    t[box][4] = { label = args.FR_total_population_estimate_year, data = "" }
    t[box][5] = { label = "Total" .. (args.FR_foot or ""), data = FR_total_population_estimate }
    t[box][6] = { label = args.FR_metropole, data = FR_metropole_population_estimate }
    t[box][7] = { label = "Density", data = population_density }
    box = box + 1
    
    -- GDP PPP box
    local GDP_PPP = args.GDP_PPP
    if ( GDP_PPP ) then
        if (args.GDP_PPP_rank) then GDP_PPP = GDP_PPP .. " ([[List of countries by GDP (PPP)|" .. args.GDP_PPP_rank .. "]])" end
    end
    local GDP_PPP_year = args.GDP_PPP_year
    if (GDP_PPP_year) then GDP_PPP_year = GDP_PPP_year .. " estimate" else GDP_PPP_year = "" end
    local GDP_PPP_per_capita = args.GDP_PPP_per_capita
    if ( GDP_PPP_per_capita ) then
        if (args.GDP_PPP_per_capita_rank) then GDP_PPP_per_capita = GDP_PPP_per_capita .. " ([[List of countries by GDP (PPP) per capita|" .. args.GDP_PPP_per_capita_rank .. "]])" end
    end
    t[box] = { single = false }
    t[box][1] = { label = "[[Gross Domestic Product|GDP]] ([[Purchasing Power Parity|PPP]])", data = GDP_PPP_year }
    t[box][2] = { label = "Total", data = GDP_PPP }
    t[box][3] = { label = "per capita", data = GDP_PPP_per_capita }
    box = box + 1
    
    -- nominal GDP box
    local GDP_nominal = args.GDP_nominal
    if ( GDP_nominal ) then
        if (args.GDP_nominal_rank) then GDP_nominal = GDP_nominal .. " ([[List of countries by GDP (nominal)|" .. args.GDP_nominal_rank .. "]])" end
    end
    local GDP_nominal_year = args.GDP_nominal_year
    if (GDP_nominal_year) then GDP_nominal_year = GDP_nominal_year .. " estimate" else GDP_nominal_year = "" end
    local GDP_nominal_per_capita = args.GDP_nominal_per_capita
    if ( GDP_nominal_per_capita ) then
        if (args.GDP_nominal_per_capita_rank) then GDP_nominal_per_capita = GDP_nominal_per_capita .. " ([[List of countries by GDP (nominal) per capita|" .. args.GDP_nominal_per_capita_rank .. "]])" end
    end
    t[box] = { single = false }
    t[box][1] = { label = "[[Gross Domestic Product|GDP]] (nominal)", data = GDP_nominal_year }
    t[box][2] = { label = "Total", data = GDP_nominal }
    t[box][3] = { label = "per capita", data = GDP_nominal_per_capita }
    box = box + 1
    
    -- GINI box
    local gini = args.Gini
    if ( gini ) then
        if (args.Gini_year) then gini = "(" .. args.Gini_year .. ") " .. gini end
        if (args.Gini_cagtegory) then gini = gini .. args.Gini_category end
        if (args.Gini_rank) then
              gini = gini .. " ([[List of countries by income equality|" .. args.Gini_rank .. "]])"
        end
    end
    t[box] = { single = false }
    t[box][1] = { label = "[[Gini coefficient|Gini]]", data = gini }
    box = box + 1
    
    -- HDI box
    local hdi = args.HDI
    if ( hdi ) then
        if (args.HDI_year) then hdi = "(" .. args.HDI_year .. ") " .. hdi end
        if (args.HDI_category) then hdi = hdi .. args.HDI_category end
        if (args.HDI_rank) then
              hdi = hdi .. " ([[List of countries by Human Development Index|" .. args.HDI_rank .. "]])"
        end
    end
    t[box] = { single = false }
    t[box][1] = { label = "[[Human Development Index|HDI]]", data = hdi }
    box = box + 1
    
    -- Currency box
    local currency = args.currency
    if ( currency ) then
        if (args.currency_code) then currency = currency .. "([[ISO 4217|" .. args.currency_code .. "]])" end
    end
    t[box] = { single = false }
    t[box][1] = { label = "Currency", data = currency }
    box = box + 1
    
    -- Antipodes box
    t[box] = { single = false }
    t[box][1] = { label = "[[Antipodes]]", data = args.antipodes }
    box = box + 1
    
    -- Date/time formats box
    t[box] = { single = false }
    t[box][1] = { label = "Date formats", data = args.date_format }
    box = box + 1
    
    -- Timezone formats box
    local time_zone = args.time_zone
    if ( time_zone ) then
        local utc_offset = args.utc_offset or args.utcoffset 
        if ( utc_offset ) then utc_offset = " [[Coordinated Universal Time|UTC]] " .. utc_offset else utc_offset = "" end
        time_zone = time_zone .. utc_offset
    end
    local time_zone_summer = args.time_zone_DST
    if ( time_zone_summer ) then
        local utc_offset = args.utc_offset_DST or args.utcoffsetdst
        if ( utc_offset ) then utc_offset = " [[Coordinated Universal Time|UTC]] " .. utc_offset else utc_offset = "" end
        time_zone_summer = time_zone_summer .. utc_offset
    end
    t[box] = { single = false }
    t[box][1] = { label = "Time zone", data = time_zone }
    t[box][2] = { label = "Summer ([[Daylight Saving Time|DST]])", data = time_zone_summer }
    t[box][3] = { label = nil, data = args.DST_note }
    box = box + 1
    
    -- Country codes box
    local iso3166code = iso3166map[pagename]
    if ( iso3166code ) then iso3166code = "[[ISO 3166-2:" .. iso3166code .. "|" .. iso3166code .. "]]"
    local calling_code_label = "[[Telephone numbers in " .. countrylink .. "|Telephone]]"
    t[box] = { single = false }
    t[box][1] = { label = "International codes", data = "" }
    t[box][2] = { label = "[[ISO 3166-2]]", data = iso3166code }
    t[box][3] = { label = calling_code_label, data = args.calling_code or args.dialingcode }
    t[box][4] = { label = "Sports", data = args.sport_code }
    t[box][5] = { label = "Vehicles", data = args.vehicle_code }
    end
    box = box + 1

    -- Rule of the road box
    t[box] = { single = false }
    t[box][1] = { label = "Drives on the", data = args.drives_on }
    box = box + 1
    
    -- Internet box
    t[box] = { single = false }
    t[box][1] = { label = "[[Country code top-level domain|ccTLD]]", data = args.cctld or args.internettld }
    t[box][2] = { label = "Website", data = args.official_website }
    box = box + 1
    
    -- Christianity box
    local patron_saint_label = "[[Patron saint]]"
    if ( args.patron_saints ) then patron_saint_label = patron_saint_label .. "s" end
    t[box] = { single = false }
    t[box][1] = { label = patron_saint_label, data = args.patron_saints or args.patron_saint }
    
    -- Another map
    local image_map3
    if ( args.image_map3 ) then
        image_map3 = "[[File:" .. args.image_map3 .. "|" .. (args.map3_width or "280px") .. "|center|alt=" .. (args.alt_map3 or args.map_caption3 or ("Location of " .. country)) .. "]]<div style=\"position:relative; top:0.3em;\"><small>" .. (args.map_caption3 or "") .."</small></div>"
    end
    t[box] = { single = false }
    t[box][1] = { image = image_map3 }
    box = box + 1

    -- Footnotes box
    t[box] = { single = true }
    t[box][1] = { label = nil, data = args.footnotes }
    for i=1,9,1 do
        local sup = mw.text.tag({name="sup", contents=i, params={}})
        local label = mw.text.tag({name="span", contents=sup, params={style="position: relative; top: 0.3em;"}})
        t[box][i + 1] = { label = label, data = args["footnote" .. i] }
    end
    box = box + 1
    
    return infobox.compound(frame, config, t)
end

return z