Module:CountryData: Difference between revisions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode Tag: Reverted |
||
| Line 346: | Line 346: | ||
end | end | ||
end | end | ||
-- Fallback for names containing " and " or "&" | |||
if not result and normalized and (normalized:find(" and ") or normalized:find("&")) then | |||
local alt = normalized | |||
if normalized:find(" and ") then | |||
alt = alt:gsub("%sand%s+", " & ") | |||
elseif normalized:find("&") then | |||
alt = alt:gsub("%s*&%s*", " and ") | |||
end | |||
local altCode = nameLookup[alt] | |||
if not altCode then | |||
local strippedAlt = DiacriticNormalization.removeDiacritics(alt) | |||
if strippedAlt ~= alt then | |||
altCode = nameLookup[strippedAlt] | |||
end | |||
end | |||
if altCode and data.countries[altCode] then | |||
result = data.countries[altCode] | |||
end | |||
end | |||
-- Cache the result (including nil) | -- Cache the result (including nil) | ||
functionCache[cacheKey] = result | functionCache[cacheKey] = result | ||
| Line 381: | Line 401: | ||
end | end | ||
-- Fallback for names containing " and " or "&" | |||
local tempCode = code | |||
if not tempCode and normalized and (normalized:find(" and ") or normalized:find("&")) then | |||
local alt = normalized | |||
if normalized:find(" and ") then | |||
alt = alt:gsub("%sand%s+", " & ") | |||
elseif normalized:find("&") then | |||
alt = alt:gsub("%s*&%s*", " and ") | |||
end | |||
local altLookup = nameLookup[alt] | |||
if not altLookup then | |||
local strippedAlt = DiacriticNormalization.removeDiacritics(alt) | |||
if strippedAlt ~= alt then | |||
altLookup = nameLookup[strippedAlt] | |||
end | |||
end | |||
tempCode = altLookup | |||
end | |||
code = tempCode | |||
-- Cache the result (including nil) | -- Cache the result (including nil) | ||
functionCache[cacheKey] = code | functionCache[cacheKey] = code | ||