Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Vés al contingut

Mòdul:lema/plantilles

De Viccionari

La documentació d'ús d'aquest mòdul es pot crear a Mòdul:lema/plantilles/ús

local p = {}

-- Suport per la plantilla:lema
function p.plantilla_lema(frame)
	local args = frame:getParent().args
	
	-- Get language and script information
	local data = {}
	local langcode = args[1] or (mw.title.getCurrentTitle().nsText == "Plantilla" and "ca") or error("Falta el codi de llengua com a primer paràmetre.")
	data.lang = require("Module:llengua").getByCode(langcode)
	if data.lang.name == langcode then
		error("El codi de llengua " .. langcode .. " no s'ha trobat.")
	end
	data.sort_key = args["ordre"]; if data.sort_key == "" then data.sort_key = nil end
	data.sc = args.sc or data.lang.sc
	
	-- Gather headwords
	data.heads = {}
	data.translits = {}
	
	local head = args["lema"] or ""
	local translit = args["tr"]; if translit == "" then translit = nil end
	local i = 1
	
	while head do
		if head then
			table.insert(data.heads, head)
			data.translits[#data.heads] = translit
		end
		
		i = i + 1
		head = args["lema" .. i]; if head == "" then head = nil end
		translit = args["tr" .. i]; if translit == "" then translit = nil end
	end
	
	-- Gather gender and number specifications
	-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
	data.genders = {}
	
	local g = args["g"]; if g == "" then g = nil end
	local i = 2
	
	while g do
		table.insert(data.genders, g)
		g = args["g" .. i]; if g == "" then g = nil end
		i = i + 1
	end
	
	-- Part-of-speech category
	data.categories = {}
	
	local langcat = " en " .. data.lang.name
	if data.lang.name == "multilingüe" then
		langcat = " multilingües"
	end
	
	local pos = args[2]; if pos == "" then pos = nil end
	local cat = args["cat"]; if cat == "" then cat = nil end
	
	if cat then
		table.insert(data.categories, cat .. langcat)
	elseif pos then
		-- Make the plural form of the part of speech
		local pos_abrev = {["abr"]="abreviatures", ["adv"]="adverbis", ["adj"]="adjectius", ["conj"]="conjuncions", 
			["interj"]="interjeccions", ["nom"]="substantius", ["num"]="numerals", ["prep"]="preposicions", ["pron"]="pronoms"}
		local pos_loc = {["adverbis"]="adverbials", ["adjectius"]="adjectivals", ["conjuncions"]="conjuntives", 
			["interjeccions"]="interjectives", ["preposicions"]="prepositives", ["substantius"]="nominals", ["verbs"]="verbals"}
		local form = string.find(pos, "-forma", -6, true)
		local loc = string.find(head or mw.title.getCurrentTitle().text, "[^ ] [^ ]")
		
		if form then
			pos = string.sub(pos, 1, form - 1)
		end
		if pos_abrev[pos] then
			pos = pos_abrev[pos]
		else
			pos, _ = require("Module:ca-lema").forma_plural_nominal(pos, "-")
		end
		
		if loc and pos_loc[pos] then
			if form then
				pos = "Formes de locucions " .. pos_loc[pos]
			else
				pos = "Locucions " .. pos_loc[pos]
			end
		elseif form then
			if pos == "verbs" then
				pos = "Formes verbals"
			elseif string.find(pos, "^[aeiou]") then
				pos = "Formes d'" .. pos
			else
				pos = "Formes de " .. pos
			end
		else
			pos = string.upper(string.sub(pos, 1, 1)) .. string.sub(pos, 2)
		end
		
		table.insert(data.categories, pos .. langcat)
	end
	
	-- Additional categories
	if args.cat2 then
		table.insert(data.categories, args.cat2 .. langcat)
	end
	
	if args.cat3 then
		table.insert(data.categories, args.cat3 .. langcat)
	end
	
	-- Inflected forms
	data.inflections = {}
	
	local i = 1
	local label = args[i * 2 + 1]
	local accel = args["f" .. i .. "accel"]; if accel == "" then accel = nil end
	local parts = {label = label, accel = accel}
	
	while label do
		local term = args[i * 2 + 2]; if term == "" then term = nil end
		local alt = args["f" .. i .. "alt"]; if alt == "" then alt = nil end
		local sc = args["f" .. i .. "sc"]; if sc == "" then sc = nil end
		local id = args["f" .. i .. "id"]; if id == "" then id = nil end
		local gender = args["f" .. i .. "g"]; if gender == "" then gender = nil end
		local qualifier = args["f" .. i .. "qual"]; if qualifier == "" then qualifier = nil end
		local nolink = args["f" .. i .. "nolink"]; if nolink == "" then nolink = nil end
		
		if term or alt then
			table.insert(parts, {term = term, alt = alt, sc = sc, id = id, translit = translit, genders = {gender}, qualifiers = {qualifier}, nolink = nolink})
		end
		
		i = i + 1
		label = args[i * 2 + 1]
		accel = args["f" .. i .. "accel"]; if accel == "" then accel = nil end
		
		-- If the next label is not "or" then insert the previous one and create a new one.
		if label ~= "o" then
			-- Only insert if the previous label is not empty.
			if (parts.label or "") ~= "" then
				table.insert(data.inflections, parts)
			end
			
			parts = {label = label, accel = accel}
		end
	end
	
	return require("Module:lema").full_headword(data)
end

return p