Modulo:Pn

Da Wikisionario

La documentazione per questo modulo può essere creata in Modulo:Pn/man

local getArgs = require('Modulo:Arguments').getArgs
local args = getArgs(frame)
local titolo = mw.title.getCurrentTitle().subpageText
local pRegex = "^[b|n|q|s|v|w|voy]" -- Regex par i projeti acetai


proj_targheta = { -- testo inte el link
	b = "testi",
	n = "notìsie",
	q = "citasion",
	s = "òpare",
	v = "corsi",
	w = "ensiclopedia",
	voy = "percoriminti",
}

proj_img = { -- titolo imàzene (sensa "-logo.ext")
	b = "Wikibooks",
	n = "Wikinews",
	q = "Wikiquote",
	s = "Wikisource",
	v = "Wikiversity",
	w = "Wikipedia",
	voy = "Wikivoyage",
}

projeti = { -- par deso no serve
	proj_targheta = {},
	proj_img = {},
}

-- funsion regex par paràmatri pasai
 local function pPattern (par)
 	return string.match ( pRegex , par)
 end
 
-- CATEGORIZAR SE NO EZISTE LA LISTA
local function categoriza(voze,lengua)
	if mw.title.new(voze).exists == false then
		return string.format('[[Category:%s]]', 'Liste in '.. lengua:lower() ..' da scrìvar') 
	else
		return ''
	end
end

--[[ FUNZIONE PER GESTIRE CATEGORIZZAZIONE E MESSAGGIO DI ERRORE
(LE VARIE CONDIZIONI NECESSARIE AL FUNZIONAMENTO SONO SPECIFICATE ALL'INTERNO
DELLA FUNZIONE Erore(), QUESTA FUNZIONE GESTISCE SOLTANTO IL RISULTATO) ]]--

local function EroreMSG (ErParametro)
	local ErMesajo = '&nbsp;<strong class="error">Parametro "<u>'.. ErParametro ..'</u>" no reconosesto</strong>'
	local ErCategoria = '[[Category:Modeło Pn co paràmetri sbajai]]'
		return ErMesajo .. '' .. ErCategoria
	end


-- FUNZIONE PER GESTIRE LA SCELTA DELL'EVENTUALE MESSAGGIO DI ERRORE PER
-- "CODICE PROGETTO ERRATO"

local function Erore (frame)
local args = getArgs(frame)
local tEr = ''	

	for i, j in pairs(args) do
		-- MESSAGGIO DI ERRORE (E CATEGORIZZAZIONE) PER CODICE PROGETTO ERRATO
		if (i ~= pPattern (i) and i ~= 'lin' and i ~= 'c' and j ~= pPattern (j)  and j ~= 'lin' and j ~= 'c') then		
			if type(i) ~= 'number' then
				tEr = EroreMSG(i)
			else
				tEr = EroreMSG(j)
			end
		end
	end
	
	return tEr
end

-- FUNZIONE PER GESTIRE IL TESTO E IL LINK AL PROGETTO WMF
local function LinkProjeto(frame)
	local args = getArgs(frame)
	local tProj = ''	

	for i, j in pairs(args) do
		-- Valore specificato per il parametro
		if type(i) ~= 'number' and i ~= 'c' or args['lin'] ~= nil then
			local img = (mw.ustring.gsub(i, '^[%a]+', proj_img))
			local targheta = (mw.ustring.gsub(i, '^[%a]+', proj_targheta))
			
			if i == pPattern (i) then -- Testo per un valore "pagina - progetto" diverso da quello di default
				tProj = "&nbsp;([[File:".. img .."-logo.svg|20px|".. img .."]] '''[["..i..":"..j.."|".. targheta .."]]''')"
			end
		end
		
		-- Valore NON specificato per il parametro
		if j ~= nil and j ~= 'c' or  args['lin'] ~= nil then
			local img = (mw.ustring.gsub(j, '^[%a]+', proj_img))
			local targheta = (mw.ustring.gsub(j, '^[%a]+', proj_targheta))
			
			if j == pPattern (j) then -- Testo per un valore "pagina - progetto" uguale a quello di default
				tProj = "&nbsp;([[File:".. img .."-logo.svg|20px|".. img .."]] '''[["..j..":"..titolo.."|".. targheta .."]]''')"
			end
		end
	end
	
	return tProj
end

-- FUNZIONE PER GESTIRE IL TESTO E IL LINK ALLA CONIUGAZIONE
local function LinkCognugasion(frame)
	local args = getArgs(frame)
	local cognugasion = ''
	local cat_cognugasion = ''
	local tCong = ''
	local SwitchLang = mw.language.fetchLanguageName( (args['c'] or args['lin'] or 'it'), 'it' )
	
		--[[ controlla che la funzione "mw.language.fetchLanguageName" non dia un 
		parametro vuoto. in caso affermativo vuol dire che il codice ISO 
		della lingua non è stato riconosciuto e quindi lo script salta del tutto
		la visualizzazione del link alla coniugazione e va direttamente al messaggio
		di errore con relativa categoria--]]
		
			for i, j in pairs(args) do
				 -- Controlla se è stato specificato il parametro "c"…
				if i == 'c' or j == 'c' or args['c'] ~= nil then
					-- … e che se è stato specificato la lingua non sia quella di default
					if args['len'] ~= nil  or args['c'] ~= nil then 
						lengua = SwitchLang:gsub("^%l", string.upper)
					else
						lengua = 'Vèneto'
					end
					
					link_cognugasion = 'Lista:Cognugasion/'..lengua..'/'.. titolo
					tCong = '&nbsp;([['..link_cognugasion..'|va inte ła cognugasion]])'..categoriza(link_cognugasion,lengua)
				end
			end
	return tCong
end

local p = {}
--[[
Funzione per creare il testo; Funziona assemblando il titolo con le due funzioni locali:
1) LinkProgetto
2) LinkConiugazione
3) Erore
--]]

	function p.pn(frame)
		local args = getArgs(frame)
		lProj = LinkProjeto(frame)
		lCong = LinkCognugasion(frame)
		Er = Erore(frame)
		
		if lProj ~= nil then
			tProj = lProj
		end
		
		if Er ~= nil then
			tEr = Er
		end
		
		if lCong ~= nil then
			tCong = lCong
		end
		
		return "'''"..titolo.."'''<small>"	.. tProj .. "" .. tCong .. "</small>" .. tEr
	end

return p
Traesto fora da Wikipèdia - L'ençiclopedia łìbara e cołaboradiva in łéngua Vèneta "https://vec.wiktionary.org/w/index.php?title=Modulo:Pn&oldid=37037"