پودمان:Infobox road/length/تمرین

توضیحات پودمان[ایجاد] [پاکسازی]
local p = {}
local convert_num = require("Module:Numeral converter").convert

local concat = table.concat
local insert = table.insert
local format = mw.ustring.format
local frame = mw.getCurrentFrame()

function p._length(num, args)
	local km = args["length_km" .. num] or args['طول به کیلومتر' .. convert_num('fa', num)] or ''
    local mi = args["length_mi" .. num] or args['طول به مایل' .. convert_num('fa', num)] or ''
    local ref = args["length_ref" .. num] or args['منبع طول' .. convert_num('fa', num)] or ''
    local notes = args["length_notes" .. num] or args['یادداشت طول' .. convert_num('fa', num)] or ''

    local first, second, unit, unit2
    if convert_num('en', mi) ~= '0' and km == '' then
        first = mi
        second = km
        unit = "mi"
        unit2 = "km"
        unit3 = "m"
    else
        first = km
        second = mi
        unit = "km"
        unit2 = "mi"
        unit3 = "mi ft"
    end

    if mi == '' and km == '' then
        return nil
    elseif notes ~= '' and convert_num('en', first) < '1' then
    	return frame:expandTemplate{ title = 'cvt', args = { first, unit, unit3, disp = "x", ref .. "&nbsp;("}} .. ")<div>" .. notes .. "</div>"
    elseif notes == '' and convert_num('en', first) < '1' then
    	return frame:expandTemplate{ title = 'cvt', args = { first, unit, unit3, disp = "x", ref .. "&nbsp;("}} .. ")<div>" .. notes .. "</div>"
    elseif notes ~= '' then
		return frame:expandTemplate{ title = 'cvt', args = { first, unit, unit2, disp = "x", ref .. "&nbsp;("}} .. ")<div>" .. notes .. "</div>"
	else
    	return frame:expandTemplate{ title = 'cvt', args = { first, unit, unit2, disp = "x", ref .. "&nbsp;("}} .. ")"
    end
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