Content deleted Content added
Revert 1080380125: Hyphen fix only |
Refactored; made output more structured |
||
Line 54:
function p.strip(text)
local accents = {["À"]="A",["Á"]="A",["Â"]="A",["Ã"]="A", --
["Ä"]="A",["Å"]="A",["Ç"]="C",["È"]="E",["É"]="E",
["Ê"]="E",["Ë"]="E",["Ì"]="I",["Í"]="I",["Î"]="I",
Line 61:
["Û"]="U",["Ü"]="U",["Ý"]="Y"
}
local remove = {"NATION OF","COUNTRY OF","TERRITORY OF", --
"FLAG OF","FLAG","KINGDOM OF","STATE OF"," STATE ",
"PROVINCE OF","PROVINCE","TERRITORY"
}
local patterns = { --
[".+:"]="",
["|.+"]="",
Line 75:
}
text = mw.ustring.upper(text) --
text = text:gsub('\195.',
for pattern,value in pairs(patterns) do --
text =
end
for _,words in pairs(remove) do --
text =
end
text = text:gsub("[^%w%-]","") --Only keep ASCII alphanumeric and hyphen
return text
Line 104 ⟶ 103:
--[[----------P . L U A C O D E---------]]-- -- Makes the ISO code of a country
-- Returns tuple (code,errorcat,errortext). code is empty string upon error because MW stops at first nil
function p.luacode(args)
if (args[1] ~= nil) then args[1] = p.strip(args[1]) end▼
local a1,a2 = args[1],args[2]
local hyphenPos = string.find(a1 or '', '-', 1, true)
if not hyphenPos then --
return
end
args[1] =
args[2] =
local
if
return
end
args[1],
return
end
local function
local country, subdivision = args[1], args[2]
Line 142 ⟶ 143:
if not country then
if mw.title.getCurrentTitle().namespace ~= 0 then catnocountry = '' end
return '',catnocountry,
end
if not subdivision then
for alpha2,cdata in pairs(data) do
if findname(alpha2,cdata,country) then
Line 156 ⟶ 157:
end
if mw.title.getCurrentTitle().namespace ~= 0 then catnocountry = '' end
return '',catnocountry
else --3166-2 code
for alpha2,cdata in pairs(data) do
if findname(alpha2,cdata,country) then
if
alpha2 = "GB"
end
Line 166 ⟶ 167:
local empty = true
for scode,scdata in pairs(sdata) do
if type(scdata) == "table" then
empty = false
if findname(scode,scdata,subdivision) then
Line 174 ⟶ 175:
end
if mw.title.getCurrentTitle().namespace ~= 0 then catnosubdivision = '' end
return '',catnosubdivision
end
end
if mw.title.getCurrentTitle().namespace ~= 0 then catnocountry = '' end
return '',catnocountry
end
Line 197 ⟶ 198:
args["codetype"]="numeric"
return p.luacode(args)
end
--[[----------P . L U A N A M E---------]]-- -- Makes the ISO/common name of a country
-- Returns tuple (name,errorcat,errortext). name is empty string upon error because MW stops at first nil
function p.luaname(args)
local code1 = p.luacode(args)
return '','','<span class="error">No such country or subdivision</span>'
local hyphenPos = string.find(code1, "-", 1, true)▼
code2 = string.sub(code1, hyphenPos+1)▼
code1 = string.sub(code1, 1, hyphenPos-1)▼
end
▲ if string.len(code1) == 2 then
if data[code1] then▼
return (args.isoname or args.lang) and isoname(data,code1,args.lang)▼
or (data[code1]["displayname"] or data[code1]["name"])▼
else▼
▲ return '[[Category:Wikipedia page with obscure country]]'
else --3166-2 code▼
▲ local sdata
if data[code1] then▼
return '',catnodata
▲ sdata = mw.loadData("Module:ISO 3166/data/"..code1)
if sdata[code2] then
return '[[Category:Wikipedia page with obscure country]]'▼
else
▲ return (args.isoname or args.lang) and isoname(sdata,code2,args.lang)
return '',catnodata
else
end
end
Line 244 ⟶ 247:
function p.name(frame)
return p.luaname(getArgs(frame))
end
Line 266 ⟶ 269:
if i == 'country' and not string.find(targs[1], 'region:', 1, true) then
local country = v
local k,
-- look for a valid subdivision
while region == '' and k < 3 do
Line 279 ⟶ 282:
if region == '' then
region = p.luacode({country, nocat = 'true'})
if mw.title.getCurrentTitle().namespace ~= 0 then catnocountry,
if region == '' then
tracking = tracking .. catnocountry
|