Content deleted Content added
No edit summary |
Adding terminus link. Imported from zh:Module:Adjacent stations/experimental by User:David Xuang |
||
Line 734:
p.station = makeInvokeFunction('_station')
function p._terminusTable(args, frame)
local system = args[1] or args.system
lineN = args[2] or args.line
typeN = args[3] or args.type
local side = mw.ustring.sub(mw.ustring.lower(args[4] or args.side or ''), 1, 1)
local prefix = (side == 'r') and 'right' or 'left'
local data = args.data
if system or data then
data = data or getData(system, true) or error(i18n[lang]['error_line'])
local line = getLine(data, lineN) or error(i18n[lang]['error_unknown'](lineN))
if typeN and data and data['aliases'] then typeN = data['aliases'][mw.ustring.lower(typeN)] or typeN end
local Type = line['types'] and line['types'][typeN]
return Type and Type[prefix .. ' terminus'] or line[prefix .. ' terminus'], data['station format'] or i18n[lang]['error_format']
end
end
function p._terminus(args, frame)
local var, Format = p._terminusTable(args, frame)
local function subst(var1, var2)
-- var1 is the terminus or table of termini; var2 is the key for the table of termini
return type(var1) == 'string' and getStation(var1, (Format[var1] or Format[1]))
or type(var1) == 'table' and #var1 > 0 and getStation(var1[var2], (Format[var1[var2]] or Format[1]))
or ''
end
if Format then
if type(var) == 'string' then
return subst(var)
elseif type(var) == 'table' and #var > 0 then
local t = {subst(var, 1)}
for i = 2, #var - 1 do
t[i] = i18n[lang]['comma'](subst(var, i))
end
if #var > 1 then t[#var] = i18n[lang]['or'](subst(var, #var)) end
if var['via'] then
if i18n[lang]['via-first'] then
table.insert(t, 1, i18n[lang]['via'](subst(var, 'via')))
else
table.insert(t, i18n[lang]['via'](subst(var, 'via')))
end
end
return table.concat(t)
else
return ''
end
else
return var or ''
end
end
p.terminus = makeInvokeFunction('_terminus')
function p._style(args, frame)
|