FANDOM


--[[FROM DEV WIKI]]--
 
--[[<pre> https://github.com/lukes/ISO-3166-Countries-with-Regional-Codes
Description : Gets data about a country  , see format in Module:Country/data
Syntax : 
{{#invoke:country|main|country-isocode|[name":"New Zealand/alpha-2/alpha-3/country-code
/sub-region-code/region-code/iso_3166-2/region/sub-region}} 
{{#invoke:country|countrycode|china}} 
* country-isocode (e.g. fr =="France")
 
]]--
 
local p = {}
local getArgs = require("Dev:Arguments").getArgs
local countryData = mw.loadData("Dev:Country/data")
 
function p.main(frame)
    local args = getArgs(frame)  
 
    if args then
        local countryCode = args[1] or args.code
        local info = args[2] or args.info
 
        return getCountryData(countryCode,info)
    end
end
 
function p.countrycode(frame)
    local args = getArgs(frame)  
 
    if args then
        local countryCode = args[1] or args.name
        local bCloseMatch = args["match"]
 
        return getCountryCode(countryCode, bCloseMatch)
    end
end
 
function getCountryData(code,info)
    if info and code then
        -- if the code doesn't exist try looking for a country name
        if not countryData[code]  then
            code = getCountryCode(code)
        end
        return countryData[code][info]
    end
end
 
function getCountryCode(name, bCloseMatch)
    name = name:lower()
    local tmpName = ""
 
    for sCode, sData in pairs(countryData) do
        tmpName= string.lower(sData.name)
 
        if tmpName == name  then
            return string.lower(sCode)
        end
        -- Try the closest match
        if sData.name:match(name) and bCloseMatch then
            return string.lower(sCode)
        end
    end
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.