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 p = {}

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

local function notVoid(param)
	if param == "" then
		return nil
	end
	return param
end

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

-- Funció d'entrada per la plantilla:trad. Original: en:Module:translations
function p.trad(frame)
    local args = frame:getParent().args
    local lang = m_languages.getByCode(args[1])
    local terminfo = {
    	lang = lang,
    	sc = args["sc"] or lang.sc,
    	term = mw.text.trim(args[2]) or (mw.title.getCurrentTitle().nsText == "Plantilla" and "terme") or nil,
    	alt = args["alt"],
    	genders = {args[3]},
    	tr = args["tr"],
    	lit = args["lit"],
    	}
	
	if lang.type then
		error("La llengua «" .. lang.name .. "» no està prevista per incloure-la en les traduccions.")
	end
	
    -- Don't show the interwiki link if there is nothing to link to.
    if terminfo.term then
		local wmlang = m_languages.wmproject(lang.code)
		
		-- 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'>(" .. lang.code .. ")</span></small></sup>"
		else
			terminfo.interwiki = "&nbsp;[[:" .. wmlang .. ":" .. m_links.sense_diacritics(lang.code, 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_languages.nom(lang) .. ']]'
end

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