Modulo:Libro

Modulo a supporto del template {{Libro}}.

Modulo:Libro
Info Istruzioni per l'uso
Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:Libro/man (modifica · cronologia)
Sandbox: Modulo:Libro/sandbox (modifica · cronologia) · Sottopagine: lista · Test: Modulo:Libro/test

Modulo a supporto del template {{Libro}}.



local getArgs = require('Module:Arguments').getArgs
local numero_romano = require('Module:Numero romano').main
local p = {}

local tab_genere = {
	["[[romanzo]]"] = "Romanzi",
	["romanzo"] = "Romanzi",
	["romanzi"] = "Romanzi",
	["serie di romanzi"] = "Romanzi",
	["[[racconto]]"] = "Racconti",
	["racconti"] = "Racconti",
	["[[racconti]]"] = "Racconti",
	["[[racconto|racconti]]"] = "Racconti",
	["racconto"] = "Racconti",
	["[[trattato]]"] = "Saggi",
	["[[trattato (opera)|trattato]]"] = "Saggi",
	["trattato"] = "Saggi",
	["[[saggistica]]"] = "Saggi",
	["saggistica"] = "Saggi",
	["[[saggi]]"] = "Saggi",
	["saggi"] = "Saggi",
	["[[saggio]]"] = "Saggi",
	["saggio"] = "Saggi"
}


local function get_genere(args)
	local gen_txt = args.genere or ''
	gen_txt = mw.ustring.lower(gen_txt)
	return tab_genere[gen_txt] or "Opere letterarie"
end

local function get_categories(year, args)
	local year_number = tonumber(year)
	if year_number then
		if year_number < 1 then
			return "Categoria:Scheda libro con anno di prima pubblicazione non riconosciuto| numero negativo"
		elseif year_number > 1800 then
			if year_number >= os.date("*t").year + 3 then
				return "Categoria:Scheda libro con anno di prima pubblicazione non riconosciuto| opera letteraria futura"
			else
				return mw.ustring.format("Categoria:%s del %s", get_genere(args), year)
			end
		else -- secoli dopo Cristo
			local century = numero_romano({math.floor( (year+99)/100 )})
			local preposizione = "del "
			if century == "VIII" or century == "XI" then
				preposizione = "dell'"
			end
			return mw.ustring.format("Categoria:%s %s%s secolo", get_genere(args), preposizione, century)
		end
	end
	return "Categoria:Scheda libro con anno di prima pubblicazione non riconosciuto"
end

function p.categories(frame)
	local args = getArgs(frame)
	local current_namespace =  mw.title.getCurrentTitle().namespace
	local cat = ''
	local force_year = args.forza_cat_anno
	local period = args.periodo
	local year = args.annoorig
	-- disattiva la categorizzazione automatica fuori da ns0
	if current_namespace ~= 0 and not args.debug then
		return period or year or ''
	end
	local wrap_category = "[[%s]]"
	if args.debug == "s" then
		wrap_category = ' [[:%s]]'
	end
	-- non definito ne periodo, ne annoorig
	if not (period or year) then
		return mw.ustring.format(wrap_category, "Categoria:Scheda libro con anno di prima pubblicazione mancante")
	end
	-- definito forza_cat_anno
	if force_year then
		-- disattivo la categorizzazione automatica se force_year = no
		if force_year:lower() == 'no' then
			return period or year
		end
		local cat = get_categories(force_year, args)
		return (period or year) .. mw.ustring.format(wrap_category, cat)
	end
	-- definito periodo
	if period then
		return period
	end
	if not(tonumber(year)) then
		local _,_,year_cleaned = string.find(year, "%[%[(%d+)%]%]")
		if year_cleaned == nil then 
			return mw.ustring.format(wrap_category, "Categoria:Scheda libro con anno di prima pubblicazione non riconosciuto")	   
		end
		year = year_cleaned
	end
	local cat = get_categories(year, args)
	return "[[" .. year .. "]]" .. mw.ustring.format(wrap_category, cat)
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.