Jump to content

Module:Infobox road/meta/mask/country

Unchecked
From Wikipedia

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

local p = {}

local countries = {}
do
    do -- United States
        local states = {"CA", "TX", "NY", "FL", "IL", "PA", "OH", "MI", "GA", "NC", "NJ", "VA", "WA", "AL", "AK", "AZ", "AR", "CO", "CT", "DE",
                        "HI", "ID", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NM", "ND",
                        "OK", "OR", "RI", "SC", "SD", "TN", "UT", "VT", "WV", "WI", "WY", "DC", "AS", "GU", "MP", "PR", "UM", "VI"}
        for i,v in ipairs(states) do
            countries[v] = "USA"
        end
    end -- United States
    do -- Canada
        local provinces = {"AB", "BC", "MB", "NB", "NL", "NS", "NT", "NU", "ON", "PE", "QC", "SK", "YT"}
        for i,v in ipairs(provinces) do
            countries[v] = "CAN"
        end
    end -- Canada
    do -- Mexico
        local states = {"AGU", "BCN", "BCS", "CAM", "CHP", "CHH", "COA", "COL", "DIF", "DUR", "GUA", "GRO", "HID", "JAL", "MEX", "MIC", "MOR",
                        "NAY", "NLE", "OAX", "PUE", "QUE", "ROO", "SLP", "SIN", "SON", "TAB", "TAM", "TLA", "VER", "YUC", "ZAC"}
        for i,v in ipairs(states) do
            countries[v] = "MEX"
        end
    end -- Mexico
    do -- Australia
        local states = {"NSW", "QLD", "SA", "TAS", "VIC"}
        for i,v in ipairs(states) do
            countries[v] = "AUS"
        end
    end -- Australia
end

p.mapping = countries

function p._country(state, country)
    if country then
        return string.upper(country)
    else
        return countries[state] or error("Country required", 0)
    end
end

function p.country(frame)
    local pframe = frame:getParent()
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template

    local state = args[1]
    local country = args[2]
    country = (country ~= '') and country or nil
    return p._country(state, country)
end

return p