Mòdul:Location map: diferència entre les revisions

Contingut suprimit Contingut afegit
mCap resum de modificació
compatibilitat coord2text amb mòdul:coordenades
Línia 103:
 
-- Finds a parameter in a transclusion of {{Coord}}.
local function coord2text(para, coord) -- this should be changed for languages which do not use Arabic numerals or the degree sign
local lat, long = mw.ustring.match(coord,'<span class="p%-latitude latitude">([^<]+)</span><span class="p%-longitude longitude">([^<]+)</span>')
if lat then
return tonumber(para == 'longitude' and long or lat)
else
lat, long = mw.ustring.match(coord, '<span class="latitude">([^<]+)</span>[, ]<span class="longitude">([^<]+)</span>')
if tonumber(lat) then
return tonumber(para == 'longitude' and long or lat)
end
end
local result = mw.text.split(mw.ustring.match(coord,'%-?[%.%d]+°[NS] %-?[%.%d]+°[EW]') or '', '[ °]')
if para == 'longitude' then result = {result[3], result[4]} end
if not tonumber(result[1]) or notand result[2] then
return tonumber(result[1]) * hemisphereMultipliers[para][result[2]]
elseif para == 'longitude' then
result = mw.text.split(long or '', '[°]')
if result[2] == 'O' then result[2] = 'W' end
else
result = mw.text.split(lat or '', '[°]')
end
if result[1] and result[2] then
return tonumber(result[1]) * hemisphereMultipliers[para][result[2]]
else
mw.log('Valor de coordenades mal format')
mw.logObject(para, 'para')
Linha 116 ⟶ 131:
return error('Valor de coordenades mal format', 2)
end
 
return tonumber(result[1]) * hemisphereMultipliers[para][result[2]]
end