Anonymous user
Module:ISO 3166: Difference between revisions
update with code from BrandonXLF per request on the talk page
(add coordinsert wrapper and simplify tracking category code) |
(update with code from BrandonXLF per request on the talk page) |
||
Line 9:
local data = mw.loadData("Module:ISO 3166/data/National")
--[[----------F I N D N A M E----------]]--
local function findname(code,cdata,qry)
end
--[[----------I S O N A M E----------]]--
function isoname(data,code,lang)
Line 51:
end
--[[----------S T R I P----------]]--
function p.strip(text)
local accents = {["À"]="A",["Á"]="A",["Â"]="A",["Ã"]="A", -- accent list
["Ä"]="A",["Å"]="A",["Ç"]="C",["È"]="E",["É"]="E",
["Ê"]="E",["Ë"]="E",["Ì"]="I",["Í"]="I",["Î"]="I",
["Ï"]="I",["Ñ"]="N",["Ò"]="O",["Ó"]="O",["Ô"]="O",
["Õ"]="O",["Ö"]="O",["Ø"]="O",["Ù"]="U",["Ú"]="U",
["Û"]="U",["Ü"]="U",["Ý"]="Y"
}
local remove = {"NATION OF","COUNTRY OF","TERRITORY OF", -- text to be removed list
"FLAG OF","FLAG","KINGDOM OF","STATE OF"," STATE ",
"PROVINCE OF","PROVINCE","TERRITORY"
}
local patterns = {[".+:"]="",["|.+"]="",["%(.-%)"]="", -- patterns to follow (order may matter)
["%..*"]="",["^THE "]="",["%_"]=" ",["%-"]=" ",
["%d%d?%d?PX"]="",
}
text = mw.ustring.upper(text) -- Case insensitivity
text = mw.ustring.gsub(text,"[À-Ý]",accents) -- Deaccent
for pattern,value in pairs(patterns) do -- Follow patterns
text = mw.ustring.gsub(text,pattern,value)
end
for _,words in pairs(remove) do -- Remove unneeded words
end
text =
return text
end
--[[----------P . C A L L S T R I P ---------]]--
function p.callstrip(frame)
Line 92 ⟶ 97:
end
--[[----------P . L U A C O D E---------]]--
function p.luacode(args)
if string.find(args[1],"%-") then
args[1], args[2] = string.match(args[1],"^([^%-]*)%-(.*)$")
end
if args[1] then args[1] = p.strip(args[1]) end
if args[2] then args[2] = p.strip(args[2]) end
if args["codetype"]=="3" then
args["codetype"]="alpha3"
Line 105 ⟶ 114:
local eot = args.error or ""
local catnocountry = (args.nocat and args.nocat == 'true') and ''
or '[[Category:Wikipedia page with obscure country]]'
local catnosubdivision = (args.nocat and args.nocat == 'true') and ''
or '[[Category:Wikipedia page with obscure subdivision]]'
if not args[1] then
return
end
if not args[2] then
else --3166-2 code
end
end
--[[----------P . C O D E---------]]--
function p.code(frame)
Line 161 ⟶ 170:
end
--[[----------P . N U M E R I C---------]]--
function p.numeric(frame)
Line 173 ⟶ 182:
end
--[[----------P . L U A N A M E---------]]--
function p.luaname(args)
Line 181 ⟶ 190:
if string.find(code1,"%-") then
end
if string.find(code1,"^%u%u$") then
or (data[code1]["displayname"] or data[code1]["name"])
else
return '[[Category:Wikipedia page with obscure country]]'
end
else --3166-2 code
local sdata
if data[code1] then
sdata = mw.loadData("Module:ISO
else
return '[[Category:Wikipedia page with obscure country]]'
end
if sdata[code2] then
return (args.isoname or args.lang)
or (sdata[code2]["displayname"] or sdata[code2]["name"])
else
return '[[Category:Wikipedia page with obscure country]]'
end
end
end
end
--[[----------P .
function p.name(frame)
return p.luaname(getArgs(frame)) or ""
end
--[[----------P . G E O C O O R D I N S E R T---------]]-- -- Wrapper for Module:Coordinates.coordinsert
function p.geocoordinsert(frame)
-- {{#invoke:ISO 3166|geocoordinsert|{{coord|...}}
Line 265 ⟶ 280:
-- otherwise, just return the coordinates
return targs[1] .. tracking
end
|