Mòdul:enllaç/plantilles

De Viccionari
Salta a la navegació Salta a la cerca
Icona de documentació de mòdul Documentació del mòdul[mostra] [modifica] [refresca]

A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]


Mòdul d'entrada per les plantilles d'enllaços: {{e}}, {{m}}, {{lleng}}. El mòdul processa els paràmetres i crida les funcions de Mòdul:enllaç. Vegeu la documentació de les plantilles corresponents per al seu ús.

local m_llengua = require("Module:llengua")
local m_links = require("Module:enllaç")

local p = {}

-- Funció d'entrada per la plantilla:e
function p.plantilla_e(frame)
	local args = frame:getParent().args
	
	local lang = args[1]
	if not m_llengua.existeix(lang) then
		error("El codi de llengua \"" .. lang .. "\" no és vàlid.")
	end
	
	local term = args[2]
	if term == "" then term = nil end
	local gloss = args["glossa"] or args["t"]
	local allowSelfLink = args["notself"] or frame.args["notself"]
	allowSelfLink = not allowSelfLink or allowSelfLink == ""
	
	-- Forward the information to full_link
	return m_links.full_link({langcode = lang, sc = args["sc"], term = term, alt = args[3], id = args["id"], tr = args["tr"], genders = {args["g"]}, gloss = gloss, pos = args["pos"], lit = args["lit"]}, nil, allowSelfLink)
end

-- Funció d'entrada per la plantilla:m
function p.plantilla_terme(frame)
	local args = frame:getParent().args
	local lang = args[1]
	local term = args[2]; if term == "" then term = nil end
	if not m_llengua.existeix(lang) then
		error("El codi de llengua \"" .. lang .. "\" no és vàlid.")
	end
	local alt = args[3] or ""; if alt == "" then alt = nil end
	local trad = args.trad or args.t; if trad == "" then trad = nil end
	local lit = args.lit; if lit == "" then lit = nil end
	local sc = args.sc; if sc == "" then sc = nil end
	local trans = args.trans or args.tr; if trans == "" then trans = nil end
	
	-- Forward the information to full_link
	return m_links.full_link({langcode = lang, sc = sc, term = term, alt = alt, id = args["id"], tr = trans, genders = {args["g"]}, gloss = trad, pos = args["pos"], lit = lit}, "terme", true)
end

-- Funció d'entrada per la plantilla:trad. Original: en:Module:translations
function p.trad(frame)
    local args = frame:getParent().args
    local terminfo = {
    	langcode = args[1],
    	sc = args["sc"] or nil,
    	term = mw.text.trim(args[2]) or (mw.title.getCurrentTitle().nsText == "Plantilla" and "terme") or nil,
    	alt = args["alt"] or nil,
    	genders = {args[3]} or nil,
    	tr = args["tr"] or nil,
    	}

    -- Don't show the interwiki link if there is nothing to link to.
    if terminfo.term then
		local wmlang = m_llengua.wmproject(terminfo.langcode)
		
		-- Don't show the interwiki link if the language is not recognised by Wikimedia
		-- or if the term contains links (for SOP translations)
		if wmlang == nil or terminfo.term:find("[[", nil, true) then
			terminfo.interwiki = "&nbsp;<sup><small><span style='color:#bbbbbb'>(" .. terminfo.langcode .. ")</span></small></sup>"
		else
			terminfo.interwiki = "&nbsp;[[:" .. wmlang .. ":" .. m_links.sense_diacritics(terminfo.langcode, terminfo.term) .. "|<sup><small>(" .. wmlang .. ")</small></sup>]]"
		end
		
		return m_links.full_link(terminfo, "trad", true)
	end
	
	return '<span style="background-color: #f0fff0; font-style:italic;">afegiu-la si la sabeu</span>[[Categoria:Traduccions demanades en ' .. m_llengua.nom(lang) .. ']]'
end

-- Funció d'entrada per la plantilla:lleng
function p.plantilla_lleng(frame)
	local args = frame:getParent().args
	local lang = args[1]; if lang == "" then lang = nil end
	local text = args[2] or ""
	local face = args["tipus"]; if face == "" then face = nil end
	
	NAMESPACE = mw.title.getCurrentTitle().nsText
	lang = lang or (NAMESPACE == "Plantilla" and "ca") or error("Falta especificar el codi de llengua")
	if not m_llengua.existeix(lang) then error("Codi de llengua incorrecte.") end
	
	local sc = args["sc"] or m_llengua.script(lang)
	
	return m_links.tag_text(text, lang, sc, face)
end

-- Temporary stopgap measure to fix [[Template:isValidPageName]].
function p.isValidPageName(frame)
	local res = mw.title.new(frame.args[1])
	if res then
		return "valid"
	else
		return ""
	end
end

return p