Module:ISO 3166/sandbox: Difference between revisions

Content deleted Content added
sync
add mw.Warning, simplify code
Line 135:
 
function p.luacode(args)
args[1], args[2] = args[1] or '', args[2] or ''
 
local code1 = p.strip(args[1])
local code2 = p.strip(args[2])
Line 143:
local eot = args.error or ""
if (code1 or "") == "" then
return cats('nocountry', args), '<span style="font-size:100%" class="error">"No parameter for the country given"</span>'
end
if (code2 or "") == "" then --3166-1 code
for alpha2,cdata in pairs(data) do
if findname(alpha2,cdata,code1) then
Line 157:
end
end
if string.find(args[1] or '',"%-") then
args[1], args[2] = string.match(args[1] or '',"^([^%-]*)%-(.*)$")
if args[2] then return p.luacode(args) end
end
mw.addWarning('ISO 3166: Unrecognized country ' .. code1 .. ' ("' .. args[1] .. '")')
return cats('nocountry', args)
else --3166-2 code
Line 182 ⟶ 183:
args[1] = args[1].."-"..code1
return p.luacode(args)
end
if args[2] ~= "" then
mw.addWarning('ISO 3166: Unrecognized subdivision ' .. code2 .. ' ("' .. args[2] .. '")')
end
return cats('nosubdivision', args)
end
end
if string.find(args[1] or '',"%-") then
args[1] = string.match(args[1] or '',"^([^%-]*)%-(.*)$")
return p.luacode(args)
end