Content deleted Content added
Fall back on not splitting by hyphen when getting code from name |
Some optimizations for luacode(): Made Hyphenation fallback lazy with more common case first; only call getArgs() once |
||
Line 100:
function p.luacode(args, skipHyphenSplit)
local country, subdivision = country, subdivision
if not skipHyphenSplit then
if string.find(
end
end
Line 108 ⟶ 110:
--error(mw.dumpObject(args))
if
if
--error(mw.dumpObject(args))
Line 124 ⟶ 126:
or '[[Category:Wikipedia page with obscure subdivision]]'
if not
if mw.title.getCurrentTitle().namespace ~= 0 then catnocountry = '' end
return catnocountry, '<span style="font-size:100%" class="error">"No parameter for the country given"</span>'
end
if not
for alpha2,cdata in pairs(data) do
if findname(alpha2,cdata,
if args["codetype"]=="numeric" or args["codetype"]=="alpha3" then
return cdata[args["codetype"]]
Line 143 ⟶ 145:
else --3166-2 code
for alpha2,cdata in pairs(data) do
if findname(alpha2,cdata,
if mw.ustring.match(alpha2,"GB") then -- For England, Wales etc.
alpha2 = "GB"
Line 152 ⟶ 154:
if type(scdata)=="table" then
empty = false
if findname(scode,scdata,
return alpha2.."-"..scode
end
Line 164 ⟶ 166:
return catnocountry
end
end
Line 170 ⟶ 172:
function p.code(frame)
local args = getArgs(frame)
-- Prioritize splitting on hyphen (subdivision).
local unhyphenateResult = p.luacode(
keepHyphenResult = p.luacode(getArgs(frame), true)▼
return keepHyphenResult▼
end▼
if unhyphenateResult ~= nil and unhyphenateResult ~= '' then
return unhyphenateResult
▲ end
-- If there is a hyphen, try again by not splitting.
if string.find(args[1] or '',"%-") then
▲ return keepHyphenResult or ''
end
return ''
|