বিষয়বস্তুতে চলুন

মডিউল:Infobox road/length

ভারতপিডিয়া থেকে
>ZI Jony কর্তৃক ১৬:৪৩, ১১ মার্চ ২০২০ তারিখে সংশোধিত সংস্করণ (হালনাগাদ করা হল)
(পরিবর্তন) ← পূর্বের সংস্করণ | সর্বশেষ সংস্করণ (পরিবর্তন) | পরবর্তী সংস্করণ → (পরিবর্তন)

এই মডিউলের জন্য মডিউল:Infobox road/length/নথি-এ নথিপত্র তৈরি করা হয়ে থাকতে পারে

local p = {}

local math = require "Module:Math"

local function getLengths(args, num)
    local precision = math._precision
    local round = math._round
    local format = math._precision_format
    local lengths = {}
    local km = args["length_km" .. num] or ''
    local mi = args["length_mi" .. num] or ''
    local prec = tonumber(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 = '০'
        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 = '০'
        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 == '০' and second == '০' then
        return
    end
    local text = {first, " ", lengths.orig, ref, " (", second, " ", lengths.comp, ")", }
    if notes ~= '' then
        table.insert(text, "<div style='font-size:90%;'>" .. notes .. "</div>")
    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 = config.num or ''
    return p._length(num, args)
end

return p