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

توضیحات پودمان[ایجاد] [پاکسازی]
local p = {}

local function countries(args, country)
    local data = {AFRICA = "no", ARAB = "no", ASIA = "no", EUR = "no", default = "yes"}
    local yesOrNo = data[country] or data.default
    if yesOrNo == "no" then
    	if args.countries then
        	return args.countries
        elseif args['کشورها'] then
        	return args['کشورها']
        end
    else
        return nil
    end
end

local function regions(args, country)
	local data = {EUR = "no", AUS = "no", AUT = "no", BIH = "no", CAN = "no", CYP = "no", CZE = "no", ESP = "no", GRC = "no", HRV = "no",
	              HUN = "no", ITA = "no", POL = "no", SGP = "no", SRB = "no", SVK = "no", SVN = "no", TUR = "no", UKR = "no", default = "yes"}
	if args.communities or args['اجتماع‌ها'] then
		return "بخش‌های<br/>خودمختار", args.communities or args['بخش‌ها']
	end
	local yesOrNo = data[country] or data.default
	if yesOrNo == "no" then
		return "بخش‌ها", args.regions or args['بخش‌ها']
	else
		return "بخش‌ها", nil
	end
end

local function states(args, country)
    local data = {AUS = "no", AUT = "no", BRA = "no", DEU = "no", IND = "no", MEX = "no", MYS = "no", USA = "no", default = "yes"}
    local yesOrNo = data[country] or data.default
    if yesOrNo == "no" then
        return args.states or args['ایالت‌ها']
    else
        return nil
    end
end

local function provinces(args, country)
    local data = {CAN = "no", CRI = "no", ESP = "no", IRN = "no", NLD = "no", PHL = "no", SAU = "no", THA = "no", TUR = "no", default = "yes"}
    local yesOrNo = data[country] or data.default
    if yesOrNo == "no" then
        return args.provinces or args['استان‌ها']
    else
        return nil
    end
end

local function counties(args, country)
    local counties = args.counties or args['شهرستان‌ها']
    local districts = args.districts or args['منطقه‌ها']
    local municipalities = args.municipalities or args['شهرداری‌ها']
    local parishes = args.parishes or args['محله‌ها']
    local boroughs = args.boroughs or args['دهکده‌ها']
    if counties then
        return "شهرستان‌ها", counties
    elseif districts then
        return "منطقه‌ها", districts
    elseif municipalities then
        return "شهرداری‌ها", municipalities
    elseif parishes then
        return "محله‌ها", parishes
    elseif boroughs then
        return "دهکده‌ها", boroughs
    else
        return '', nil
    end
end

local function ruralMunis(args, country)
    local label
    local province = country or ''
    if province == "AB" then
        label = "شهرداری‌های<br/>تخصصی<br/>و روستایی"
    elseif province == "ON" then
    	label = "شهرداری‌ها"
    else
        label = "شهرداری‌های<br/>روستایی"
    end
    local data = {AB = "no", BC = "no", MB = "no", NB = "no", NL = "no", ON = "no", PE = "no", QC = "no", SK = "no", default = "yes"}
    local yesOrNo = data[province] or data.default
    if yesOrNo == "no" then
        return label, args.rural_municipalities or args['شهرداری‌های روستایی']
    else
        return '', nil
    end
end

local function divisions(args, country)
    local province = country or ''
    local data = {ON = "no", default = "yes"}
    local yesOrNo = data[province] or data.default
    if yesOrNo == "no" then
        return args.divisions or args['قسمت‌ها']
    else
        return nil
    end
end

local function cities(args, country, parameter, fa_parameter)
    local data = {USA = "yes", default = "no"}
    local yesOrNo = data[country] or data.default
    if yesOrNo == "no" then
        return args[parameter] or args[fa_parameter]
    else
        return nil
    end
end

local function destinations(args, country)
    local label
    if country == "GBR" then
        label = "[[:en:Primary status|مقصدهای<br/>اصلی]]"
    else
        label = "مقصدهای<br/>اصلی"
    end
    local data = {AUS = "no", GBR = "no", IMN = "no", IND = "no", IRL = "no", MYS = "no", NIR = "no", NPL = "no", NZL = "no", default = "yes"}
    local yesOrNo = data[country] or data.default
    if yesOrNo == "no" then
        return label, args.destinations or args['مقصدها']
    else
        return '', nil
    end
end

local function lga(args, country)
    local labels = {SA = "[[مناطق دولت محلی در استرالیای جنوبی|منطقه(های)<br/>دولت محلی]]", VIC = "[[دولت محلی در ویکتوریا||منطقه(های)<br/>دولت محلی]]", NSW = "[[مناطق دولت محلی در نیو ساوت ولز||منطقه(های)<br/>دولت محلی]]",
                    QLD = "[[مناطق دولت محلی کوئینزلند||منطقه(های)<br/>دولت محلی]]", NT = "[[مناطق دولت محلی قلمرو شمالی||منطقه(های)<br/>دولت محلی]]",
                    WA = "[[مناطق دولت محلی استرالیای غربی||منطقه(های)<br/>دولت محلی]]", TAS = "[[مناطق دولت محلی تاسمانی||منطقه(های)<br/>دولت محلی]]", ACT = "منطقه(ها)"}
    local data = {AUS = "no", default = "yes"}
    local yesOrNo = data[country] or data.default
    if yesOrNo == "no" then
        local state = args.state or args['ایالت'] or ''
        local label = labels[state] or "[[دولت محلی در استرالیا|منطقه(های)<br/>دولت محلی]]"
        return label, args.lga or args['منطقه دولت محلی']
    else
        return '', nil
    end
end

local function locations(args, country)
    local labels = { highway = "شهرک‌های بزرک", ['بزرگراه'] = "شهرک‌های بزرک",
    	["rural road"] = "شهرک‌های بزرک", ["جاده روستایی"] = "شهرک‌های بزرک",
    	freeway = "حومه‌های بزرگ", ["آزادراه"] = "مناطق بزرگ<br/<برون‌شهری", 
    	["city highway"] = "حومه‌های بزرگ", ["بزرگراه شهری"] = "حومه‌های بزرگ",
    	road = "حومه‌های بزرگ", ["جاده"] = "حومه‌های بزرگ",
    	street = "حومه‌ها", ["خیابان"] = "حومه‌ها" }
    local data = {AUS = "no", default = "yes"}
    local yesOrNo = data[country] or data.default
    if yesOrNo == "no" then
        local type = args.type or args['نوع'] or ''
        local label = labels[type] or "مقصدهای<br/>اصلی"
        return label, args.locations or args['موقعیت‌ها']
    else
        return '', nil
    end
end

function p.locations(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 parameters = {label1 = "کشورها", label3 = "ایالت‌ها", label4 = "استان‌ها", label7 = "بخش‌ها", label8 = "شهرهای بزرگ",
                        label9 = "شهرک‌ها", label10 = "روستاها", child = "yes", decat = "yes", labelstyle = "text-align:left", title = "موقعیت"}
    local data = {}
    
    local function emptyParam(param)
        if param == '' then
            return nil
        else
            return param
        end
    end

    local country = emptyParam(args.country or args['کشور'])
    local state = emptyParam(args.state or args['ایالت'])
    local province = emptyParam(args.province or args['استان'])
    if not(country) then
        local stateParam = args.state or args['ایالت'] or args.province or args['استان']
        if not(stateParam) then
            country = ''
        else
            local countryMask = require "Module:Infobox road/meta/mask/country"
            country = countryMask._country(stateParam, country)
        end
    end
    data[1] = countries(args, country)
    parameters.label2, data[2] = regions(args, country)
    data[3] = states(args, country)
    data[4] = provinces(args, country)
    parameters.label5, data[5] = counties(args, country)
    parameters.label6, data[6] = ruralMunis(args, province)
    data[7] = divisions(args, province or args['استان'])
    data[8] = cities(args, country, 'cities', 'شهرها')
    data[9] = cities(args, country, 'towns', 'شهرک‌ها')
    data[10] = cities(args, country, 'villages', 'روستاها')
    parameters.label11, data[11] = destinations(args, country)
    parameters.label12, data[12] = lga(args, country)
    parameters.label13, data[13] = locations(args, country)
    
    local hasData = false
    for k,v in pairs(data) do
        if v ~= '' then
            hasData = true
            break
        end
    end
    if not(hasData) then
        return ''
    end
    
    for k,v in pairs(data) do
        parameters["data" .. k] = v
    end
    
    local infoboxModule = require 'Module:Infobox'
    return infoboxModule.infobox(parameters)
end

return p