Source of truth for Zelda-related regions. See Module:UtilsRegion/Data.
This module exports the following functions.region
region(code)
- Returns
- The name of the region for the given code, or nil if none found.
- Examples
Input | Output | Result | Status |
---|---|---|---|
region("BR")
| "Brazil" | Brazil | |
region("NOA")
| "North America" | North America | |
region("foo")
| nil
|
flag
flag(code, [size])
- Parameters
- Returns
- Image thumbnail of the flag associated to the given region code, or nil if none found.
- Examples
Input | Output | Result | Status |
---|---|---|---|
flag("CA")
| '<span title="Canada" class="explain">[[File:Canada Flag.png|20px|Canada]]</span>' | ![]() | |
flag("EUR", "60px")
| "[[File:European Union Flag.png|60px|Europe]]" | ![]() | |
flag("foo")
| nil
|
local p = {}
local utilsLayout = require("Module:UtilsLayout")
local utilsMarkup = require("Module:UtilsMarkup")
local utilsTable = require("Module:UtilsTable")
local data = require("Module:UtilsRegion/Data")
function p.region(code)
local region = data[code]
if region and region.name then
region = region.name
end
return region
end
function p.flag(code, size)
local imgSize = size or "20px"
local region = data[code]
if not region then
return nil
end
local file = region.flag or ("File:%s Flag.png"):format(region)
local caption = region.name or region
local img = utilsMarkup.file(file, {
size = imgSize,
caption = caption
})
if size then
return img
else
return utilsMarkup.tooltip(img, caption)
end
end
function p.enum()
local enum = utilsTable.keys(data)
enum.reference = "[[Module:UtilsRegion/Data]]"
return enum
end
function p.Data()
local rows = {}
for code in pairs(data) do
table.insert(rows, {
code,
p.region(code),
p.flag(code)
})
end
rows = utilsTable.sortBy(rows, 1)
return utilsLayout.table({
sortable = true,
headers = {"Code", "Region", "Flag"},
rows = rows
})
end
p.Schemas = {
Data = {
type = "map",
required = true,
keys = { type = "string" },
values = {
oneOf = {
region = {
type = "record",
properties = {
{
name = "name",
type = "string",
required = true,
desc = "Name of the region.",
},
{
name = "flag",
type = "string",
required = true,
desc = "Filename for the region's flag.",
},
},
},
country = {
type = "string",
desc = "The name of the country as a string. Must also be the prefix of its [[:Category:Flags|flag]]'s filename.",
},
},
}
},
flag = {
size = {
type = "string",
default = "20px",
},
}
}
p.Documentation = {
region = {
params = {"code"},
returns = "The name of the region for the given code, or nil if none found.",
cases = {
{
args = {"BR"},
expect = "Brazil",
},
{
args = {"NOA"},
expect = "North America",
},
{
args = {"foo"},
expect = nil
},
},
},
flag = {
params = {"code", "size"},
returns = "Image thumbnail of the flag associated to the given region code, or nil if none found.",
cases = {
{
args = {"CA"},
expect = '<span title="Canada" class="explain">[[File:Canada Flag.png|20px|Canada]]</span>',
},
{
args = {"EUR", "60px"},
expect = "[[File:European Union Flag.png|60px|Europe]]",
},
{
args = {"foo"},
expect = nil
},
}
},
}
return p