پودمان:Jcttop/core

از ویکی‌پدیا، دانشنامهٔ آزاد
توضیحات پودمان[نمایش] [ویرایش] [تاریخچه] [پاکسازی]

این پودمان برای پیاده‌سازی {{jcttop/core}} کاربرد دارد.

local p = {}
local yesno = require('Module:Yesno')

local format = mw.ustring.format -- Local version of string formatting function

local function hatnote(args)
	local insert = table.insert
	local text = {args.region_note or args['یادداشت منطقه']}
	local tense
	
	local hatnoteArg = args.hatnote or args['سرنویس']
	if hatnoteArg == 'off' or hatnoteArg == 'خاموش' then
		insert(text, '')
	elseif hatnoteArg then
		insert(text, hatnoteArg .. " ")
	else
		local indep_city = args.indep_city or args['شهر مستقل']
		local sub1 = args.sub1 or args['زیر۱']
		local sub2 = args.sub2 or args['زیر۲']
		if indep_city or sub1 or sub2 then
			local region = args.region or args['منطقه']
			tense = yesno(args.former or args['سابق'])
			
			--  Modified for standard Persian wording. update with caution!
			-- می‌دهد: کل [مسیر] در [[شهر، استان|شهر]] قرار [داشته‌است|دارد]
			
			--	insert(text, format("The entire %s %s in ", args.type or 'route', verb))
			--	if indep_city then
			--		insert(text, format("[[%s, %s|%s]]", indep_city, region, indep_city))
			--	else 
			
			local verb = tense and 'داشته‌است' or 'دارد'
			insert(text, format("کل %s در ", args.type or args['نوع'] or 'مسیر'))
			if indep_city then
				insert(text, format("[[%s، %s|%s]] قرار %s", indep_city, region, indep_city, verb))
			else
				local sub1name = args.sub1name or args['نام زیر۱']
				if sub2 then
					insert(text, "[[" .. sub2)
					local area = args.area or args['محدوده']
					if area then
						insert(text, format(" (%s)", area))
					end
					if yesno(args.sub1dab or args['ابهام‌زدایی زیر۱']) then
						insert(text, format("، %s %s", sub1, sub1name))
					end
					insert(text, format("، %s|%s]]", region, sub2))
				end
				if sub1 then
					if sub2 then
						insert(text, '، ')
					end
					insert(text, format("[[%s %s، %s|%s %s]] قرار %s", sub1name, sub1, region, sub1name, sub1, verb))
				end
			end
		insert(text, '. ')
		insert(text, args.sub1_ref or args['منبع زیر۱'])
		insert(text, args.sub2_ref or args['منبع زیر۲'])
		end
	end
	
	if yesno(args.unnum or args['بدون شماره']) then
		insert(text, format("تمامی خروجی‌ها بدون شماره %s.", tense and 'بوده‌اند' or 'هستند'))
	end
	
	return mw.text.trim(table.concat(text))
end

local function header(args)
	local row = mw.html.create('tr')
	local region_col = args.region_col or args['ستون منطقه']
	if region_col then
		row:tag('th'):attr('scope', 'col'):wikitext(mw.language.getContentLanguage():ucfirst(region_col))
	end
	
	local indep_city = args.indep_city or args['شهر مستقل']
	if not(yesno(args.nosub1 or args['برون زیر۱']) or args.sub1 or args['زیر۱'] or indep_city or args['شهر مستقل']) then
		local tag = row:tag('th'):attr('scope', 'col')
		local sub1disp = args.sub1disp or args['نمایش زیر۱']
		if sub1disp then
			tag:wikitext(sub1disp)
		else
			tag:wikitext(args.sub1name or args['نام زیر۱']):wikitext(args.sub1_ref or args['منبع زیر۱'])
		end
	end
	
	if not(args.sub2 or args['زیر۲'] or indep_city or args['شهر مستقل']) then
		row:tag('th'):attr('scope', 'col')
			:wikitext(args.location_def or args['پیش‌فرض موقعیت'] or 'موقعیت'):wikitext(args.sub2_ref or args['منبع زیر۲'])
	end
	
	local altunit = args.altunit or args['واحد جایگزین']
	if altunit then
		row:tag('th'):attr('scope', 'col'):wikitext(altunit):wikitext(args.altunit_ref or args['منبع واحد جایگزین'])
	else
		local unit = args.length or args['طول'] or args.unit or args['واحد']
		if unit ~= 'off' and unit ~= 'خاموش' then
			row:tag('th'):attr('scope', 'col'):wikitext(unit):wikitext(args.length_ref or args['منبع طول']):done():tag('th'):attr('scope', 'col'):wikitext(args.unit2 or args['واحد۲'])
		end
	end
	
	local exit = args[1]
	if exit == 'old' or exit == 'قدیمی' then
		row:tag('th'):attr('scope', 'col'):wikitext(args.old_def or args['پیش‌فرض قدیمی'] or 'خروجی قدیمی'):wikitext(args.old_ref or args['منبع قدیمی'])
		row:tag('th'):attr('scope', 'col'):wikitext(args.exit_def or args['پیش‌فرض خروجی'] or 'خروجی جدید'):wikitext(args.exit_ref or args['منبع خروجی'])
	elseif exit == 'exit' or exit == 'خروجی' then
		row:tag('th'):attr('scope', 'col'):wikitext(args.exit_def or args['پیش‌فرض خروجی'] or 'خروجی'):wikitext(args.exit_ref or args['منبع خروجی'])
	end
	
	if args[2] == 'name' or args[2] == 'نام' then
		row:tag('th'):attr('scope', 'col'):wikitext(args.name_def or args['پیش‌فرض نام'] or 'نام'):wikitext(args.name_ref or args['منبع نام'])
	end
	
	row:tag('th'):attr('scope', 'col'):wikitext(args.dest_def or args['پیش‌فرض مقصد'] or 'مقصدها'):wikitext(args.dest_ref or args['منبع مقصد'])
	
	row:tag('th'):attr('scope', 'col'):wikitext(args.notes_def or args['پیش‌فرض توضیحات'] or 'توضیحات'):wikitext(args.notes_ref or args['منبع توضیحات'])
	
	return '\n{| class="plainrowheaders wikitable"\n' .. tostring(row)
end

function p._jcttop(args)
	-- This function calls two other functions to generate a hatnote and header row.
	-- This function is accessible from other Lua modules.
	return hatnote(args) .. header(args)
end

function p.jcttop(frame)
	-- Entry function for {{jcttop/core}}
	return p._jcttop(require('Module:Arguments').getArgs(frame)) -- Simply call another function with those arguments to actually create the header.
end

return p