Module:Infobox road/length
لاسوند لپاره ددې موډيول کېدای سی په Module:Infobox road/length/لاسوند کي وي
local p = {}
local math = require "Module:Math"
local convert = require("Module:Numeral converter").convert
local function getLengths(args, num)
local precision = math._precision
local round = math._round
local format = math._precision_format
local lengths = {}
local km = convert("en", args["length_km" .. num] or '')
local mi = convert("en", args["length_mi" .. num] or '')
local prec = tonumber(convert("en", args["length_round" .. num]))
if '' == km then
local n = tonumber(mi)
prec = prec or precision(mi)
if n then
lengths.km = format(tostring(n * 1.609344), tostring(prec))
else
lengths.km = '0'
end
else
prec = prec or precision(km)
lengths.km = format(km, tostring(prec))
lengths.orig = "کیلومتر"
lengths.comp = "ميل"
end
if '' == mi then
local n = tonumber(km)
prec = prec or precision(km)
if n then
lengths.mi = format(tostring(n / 1.609344), tostring(prec))
else
lengths.mi = '0'
end
else
prec = prec or precision(mi)
lengths.mi = format(mi, tostring(prec))
lengths.orig = "مایل"
lengths.comp = "کیلومتر"
end
return lengths
end
function p._length(num, args)
local ref = args["length_ref" .. num] or ''
local notes = args["length_notes" .. num] or ''
local lengths = getLengths(args, num)
local first, second
if lengths.orig == "ميل" then
first = lengths.mi
second = lengths.km
else
first = lengths.km
second = lengths.mi
end
if first == '0' and second == '0' then
return
end
local text = {convert("ps", first), " ", lengths.orig, ref, " (", convert("ps", second), " ", lengths.comp, ")", }
if notes ~= '' then
table.insert(text, "<br><small>" .. notes .. "</small>")
end
return table.concat(text)
end
function p.length(frame)
local pframe = frame:getParent()
local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
local num = convert("en", config.num or '')
return p._length(num, args)
end
return p