Module:German coord convert: Difference between revisions
Appearance
Content deleted Content added
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
-- This module converts German Wikipedia-style coordinates to a formatted |
|||
-- invocation of the [[template:coord]] template |
|||
local p = {} |
local p = {} |
||
function p.main(frame) |
function p.main(frame) |
||
local latstr = frame.args[1] or '' |
|||
local lonstr = frame.args[2] or '' |
|||
if mw.ustring.match(c, '^[%s]*([0-9][0-9]*)[%s]*/[%s]*([0-9][0-9]*)[%s]*/[%s]*([0-9][0-9%.]*)[%s]*/[%s]*[NEO][%s]*$') then |
|||
local tstr = frame.args[3] or '' |
|||
local d, m, s = mw.ustring.match(c, '^[%s]*([0-9][0-9]*)[%s]*/[%s]*([0-9][0-9]*)[%s]*/[%s]*([0-9][0-9%.]*)[%s]*/[%s]*[NEO][%s]*$') |
|||
local fstr = frame.args['format'] or '' |
|||
return math.floor(1000000*(tonumber(d) + tonumber(m)/60 + tonumber(s)/3600) + 0.5)/1000000 |
|||
local dstr = frame.args['display'] or '' |
|||
⚫ | |||
local nmstr = frame.args['name'] or '' |
|||
if mw.ustring.match(c, '^[%s]*([0-9][0-9]*)[%s]*/[%s]*([0-9][0-9]*)[%s]*/[%s]*([0-9][0-9%.]*)[%s]*/[%s]*[SW][%s]*$') then |
|||
local ntstr = frame.args['notes'] or '' |
|||
local d, m, s = mw.ustring.match(c, '^[%s]*([0-9][0-9]*)[%s]*/[%s]*([0-9][0-9]*)[%s]*/[%s]*([0-9][0-9%.]*)[%s]*/[%s]*[SW][%s]*$') |
|||
local issubst= frame.args['subst'] or '' |
|||
return -1*math.floor(1000000*(tonumber(d) + tonumber(m)/60 + tonumber(s)/3600) + 0.5)/1000000 |
|||
⚫ | |||
latstr = mw.ustring.gsub(latstr, '[%s]', '') |
|||
return c |
|||
lonstr = mw.ustring.gsub(lonstr, '[%s]', '') |
|||
latstr = mw.ustring.gsub(latstr, ',', '.') |
|||
lonstr = mw.ustring.gsub(lonstr, ',', '.') |
|||
latstr = mw.ustring.gsub(latstr, '[Oo]', 'E') |
|||
if (issubst ~= '') then |
|||
local res = '' |
|||
if (tstr ~= '' ) then |
|||
res = '|' .. tstr |
|||
end |
|||
if (fstr ~= '' ) then |
|||
res = res .. '|format=' .. fstr |
|||
end |
|||
if (dstr ~= '' ) then |
|||
res = res .. '|display=' .. dstr |
|||
end |
|||
if (nmstr ~= '' ) then |
|||
res = res .. '|name=' .. nmstr |
|||
end |
|||
if (ntstr ~= '' ) then |
|||
res = res .. '|notes=' .. ntstr |
|||
end |
|||
latstr = mw.ustring.gsub(latstr, '/[/]*', '|') |
|||
lonstr = mw.ustring.gsub(lonstr, '/[/]*', '|') |
|||
return '{{coord|' .. latstr .. '|' .. lonstr .. res .. '}}' |
|||
else |
|||
local targs = mw.text.split( latstr .. '/' .. lonstr, '/[/]*') |
|||
if tstr ~= '' then |
|||
targs[#targs] = tstr |
|||
⚫ | |||
if fstr ~= '' then |
|||
targs['format'] = fstr |
|||
⚫ | |||
if dstr ~= '' then |
|||
targs['display'] = dstr |
|||
end |
|||
if nmstr ~= '' then |
|||
targs['name'] = nmstr |
|||
end |
|||
if ntstr ~= '' then |
|||
targs['notes'] = ntstr |
|||
end |
|||
return frame:expandTemplate{ 'coord', args = targs } |
|||
end |
|||
end |
end |
||
return p |
return p |
Revision as of 14:59, 23 January 2017
-- This module converts German Wikipedia-style coordinates to a formatted
-- invocation of the [[template:coord]] template
local p = {}
function p.main(frame)
local latstr = frame.args[1] or ''
local lonstr = frame.args[2] or ''
local tstr = frame.args[3] or ''
local fstr = frame.args['format'] or ''
local dstr = frame.args['display'] or ''
local nmstr = frame.args['name'] or ''
local ntstr = frame.args['notes'] or ''
local issubst= frame.args['subst'] or ''
latstr = mw.ustring.gsub(latstr, '[%s]', '')
lonstr = mw.ustring.gsub(lonstr, '[%s]', '')
latstr = mw.ustring.gsub(latstr, ',', '.')
lonstr = mw.ustring.gsub(lonstr, ',', '.')
latstr = mw.ustring.gsub(latstr, '[Oo]', 'E')
if (issubst ~= '') then
local res = ''
if (tstr ~= '' ) then
res = '|' .. tstr
end
if (fstr ~= '' ) then
res = res .. '|format=' .. fstr
end
if (dstr ~= '' ) then
res = res .. '|display=' .. dstr
end
if (nmstr ~= '' ) then
res = res .. '|name=' .. nmstr
end
if (ntstr ~= '' ) then
res = res .. '|notes=' .. ntstr
end
latstr = mw.ustring.gsub(latstr, '/[/]*', '|')
lonstr = mw.ustring.gsub(lonstr, '/[/]*', '|')
return '{{coord|' .. latstr .. '|' .. lonstr .. res .. '}}'
else
local targs = mw.text.split( latstr .. '/' .. lonstr, '/[/]*')
if tstr ~= '' then
targs[#targs] = tstr
end
if fstr ~= '' then
targs['format'] = fstr
end
if dstr ~= '' then
targs['display'] = dstr
end
if nmstr ~= '' then
targs['name'] = nmstr
end
if ntstr ~= '' then
targs['notes'] = ntstr
end
return frame:expandTemplate{ 'coord', args = targs }
end
end
return p