La documentación para este módulo puede ser creada en Módulo:pron-graf/doc

local export = {}

local insert = table.insert
local concat = table.concat

local argumentos_simples = {"d", "ac", "ls", "nl", "ts", "tl", "e", "g", "v", "h", "p", "s", "rima"}
local argumentos_nombres = {"silabación", "acentuación", "longitud silábica", "número de letras", "transcripciones silábicas", "transliteraciones", "escrituras alternativas", "grafías alternativas", "variantes", "homófonos", "parónimos", "símbolos", "rimas"}
local argumentos_links = {false, false, false, false, false, false, true, true, true, true, true, true, false}
local booleano = require("Módulo:sí-no")
local obtener_idioma = require("Módulo:lenguas").cod_a_idioma
local sortkey = require("Módulo:sortkey").generarSortkey
local generar_error = require("Módulo:traza")

local pron_auto = {
	["es"] = true,
	["alc"] = true,
	["ang"] = true,
	["ar"] = true,
	["arn"] = true,
	["ast"] = true,
	["az"] = true,
	["azd"] = true,
	["azn"] = true,
	["azz"] = true,
	["ca"] = true,
	["cub"] = true,
	["eo"] = true,
	["eu"] = true,
	["ext"] = true,
	["fi"] = true,
	["fr"] = true,
	["gn"] = true,
	["grc"] = true,
	["hbo"] = true,
	["he"] = true,
	["hy"] = true,
	["it"] = true,
	["la"] = true,
	["naz"] = true,
	["nch"] = true,
	["nci"] = true,
	["ncj"] = true,
	["ncl"] = true,
	["ncx"] = true,
	["ngu"] = true,
	["nhc"] = true,
	["nhe"] = true,
	["nhg"] = true,
	["nhi"] = true,
	["nhk"] = true,
	["nhm"] = true,
	["nhn"] = true,
	["nht"] = true,
	["nhv"] = true,
	["nhw"] = true,
	["nhx"] = true,
	["nhy"] = true,
	["nlv"] = true,
	["nsu"] = true,
	["nuz"] = true,
	["pl"] = true,
	["pt"] = true,
	["ro"] = true,
	["ru"] = true,
	["sh"] = true,
	["sk"] = true,
	["tok"] = true,
	["uk"] = true,
	["yua"] = true,
}

function export.mostrar(frame)

	local params = {
		[1] = {alias_de = "fone"},
		["leng"] = {por_defecto = "es", requerido = true},
		["alt"] = {},
		["ayuda"] = {lista = true},
		["ayudaextra"] = {lista = true},
		["pron"] = {lista_doble = true},
		["fone"] = {lista_doble = true},
		["fono"] = {lista_doble = true},
		["fgraf"] = {lista_doble = true},
		["fnota"] = {lista_doble = true},
		["audio"] = {lista_doble = true},
		["aunota"] = {lista_doble = true},
		["ac"] = {lista = true},
		["acentuación"] = {alias_de = "ac"},
		["ls"] = {lista = true, tipo = "num"},
		["longitud_silábica"] = {alias_de = "ls"},
		["nl"] = {tipo = "num"},
		["número_letras"] = {alias_de = "nl"},
		["d"] = {lista = true},
		["div"] = {alias_de = "d"},
		["división"] = {alias_de = "d"},
		["dnota"] = {lista = true},
		["ts"] = {lista = true},
		["transcripción silábica"] = {alias_de = "ts"},
		["tsnota"] = {lista = true},
		["tl"] = {lista = true},
		["transliteración"] = {alias_de = "tl"},
		["tlalt"] = {lista = true},
		["tlnum"] = {lista = true},
		["tlnúm"] = {alias_de = "tlnum"},
		["tlnota"] = {lista = true},
		["e"] = {lista = true},
		["ea"] = {alias_de = "e"},
		["escritura alternativa"] = {alias_de = "e"},
		["ealt"] = {lista = true},
		["enum"] = {lista = true},
		["enúm"] = {alias_de = "enum"},
		["enota"] = {lista = true},
		["g"] = {lista = true},
		["ga"] = {alias_de = "g"},
		["grafía alternativa"] = {alias_de = "g"},
		["galt"] = {lista = true},
		["gnum"] = {lista = true},
		["gnúm"] = {alias_de = "gnum"},
		["gnota"] = {lista = true},
		["v"] = {lista = true},
		["variante"] = {alias_de = "v"},
		["valt"] = {lista = true},
		["vnum"] = {lista = true},
		["vnúm"] = {alias_de = "vnum"},
		["vtr"] = {lista = true},
		["vnota"] = {lista = true},
		["h"] = {lista = true},
		["homófono"] = {alias_de = "h"},
		["halt"] = {lista = true},
		["hnum"] = {lista = true},
		["hnúm"] = {alias_de = "hnum"},
		["htr"] = {lista = true},
		["hnota"] = {lista = true},
		["p"] = {lista = true},
		["parónimo"] = {alias_de = "p"},
		["palt"] = {lista = true},
		["pnum"] = {lista = true},
		["pnúm"] = {alias_de = "pnum"},
		["ptr"] = {lista = true},
		["pnota"] = {lista = true},
		["s"] = {lista = true},
		["símbolo"] = {alias_de = "s"},
		["salt"] = {lista = true},
		["snum"] = {lista = true},
		["snúm"] = {alias_de = "snum"},
		["snota"] = {lista = true},
		["rima"] = {lista = true},
	}
	local parent_frame = frame:getParent()
	local args = require("Módulo:parámetros").obtener_parametros(parent_frame.args, params)
	local title_ = mw.title.getCurrentTitle()
	local title = title_.fullText -- no sirve parent_frame:getTitle()
	local ns = title_.namespace
	local LENG = args["leng"]:upper()
	local leng = args["leng"]
	local idioma, sk
	if ns == 0 then
		idioma = obtener_idioma(leng)
		sk = sortkey(title, leng, idioma)
	end
	--local frame = mw.getCurrentFrame()
	
	if args["nl"] then
		generar_error("nl")
	end
	if args["alt"] then
		generar_error("alt")
	end
	
	if args["ts"][1] or args["tsnota"][1] or args["tlnum"][1] or args["enum"][1] or args["gnum"][1] or args["vnum"][1] or args["hnum"][1] or args["vtr"][1] or args["htr"][1] or args["pnum"][1] or args["ptr"][1] or args["s"][1] then
		generar_error("extra")	
	end
	
	if args["pron"][1] and booleano(args["pron"][1][1], true) == false then
		return nil
	end
	
	local table_markup = {}
	insert(table_markup, '{|class="pron-graf toccolours" style="float: right;"\n|style="background:#DBDBDB; color:#000;" colspan="2"|<span style="font-family: Arial, sans-serif; font-size: 1.5em;">'..(args["alt"] and args["alt"] or title)..'</span>\n')

	if pron_auto[leng] then
		args = require("Módulo:generar-pron/"..leng).procesar_pron_args(title, args)	
	end

	local N = math.max(#args["fone"], #args["fono"])

	if N == 0 then
		insert(table_markup, "|-\n|'''pronunciación'''" .. '\n|<span style="color: green; font-size: 90%; font-style: italic;"> falta [[Wikcionario:Pronunciación|agregar]]</span>[[Categoría:'..LENG..':Palabras sin transcripción fonética]]\n')
	else
		for i = 1,9 do
			if args["fone"][i] or args["fono"][i] then
				insert(table_markup, '|-\n')
				if args["pron"][i] and args["pron"][i][1] then
					insert(table_markup, '|'..'[[Wikcionario:Referencia/'..LENG.."/Pronunciación|'''"..args["pron"][i][1].."''']]"..' ([[Alfabeto Fonético Internacional|AFI]])'..'\n|')
				else
					insert(table_markup, '|'..'[[Wikcionario:Referencia/'..LENG.."/Pronunciación|'''pronunciación''']]"..' ([[Alfabeto Fonético Internacional|AFI]])'..'\n|')
				end
				for j = 1,9 do
					local br = false
					local fone_espacio = false
					local graf_espacio = false
					if args["fgraf"][i] and args["fgraf"][i][j] then
						insert(table_markup, "'''"..args["fgraf"][i][j].."''' ")
						graf_espacio = true
					end
					if args["fone"][i] and args["fone"][i][j] then
						insert(table_markup, graf_espacio and ' ['..args["fone"][i][j]..']' or '['..args["fone"][i][j]..']')
						fone_espacio = true
						br = true
					end
					if args["fono"][i] and args["fono"][i][j] then
						insert(table_markup, fone_espacio and ' /'..args["fono"][i][j]..'/' or '/'..args["fono"][i][j]..'/')
						br = true
					end
					if args["fnota"][i] and args["fnota"][i][j] then
						insert(table_markup, ' ('..args["fnota"][i][j]..')')
						br = true
					end
					if args["audio"][i] and args["audio"][i][j] then
						if args["aunota"][i] and args["aunota"][i][j] then
							insert(table_markup, " "..frame:extensionTag("phonos", frame:extensionTag("small", "''"..args["aunota"][i][j].."''"), {class = "pron-graf", file = args["audio"][i][j], leng = args["leng"]}))
						else
							insert(table_markup, " "..frame:extensionTag("phonos", nil, {file = args["audio"][i][j], leng = args["leng"]}))
						end
						br = true
					end
					if br then
						insert(table_markup, '<br/>') --salto de línea sin cambiar de fila
					end
				end
				insert(table_markup, '\n')
			end
		end
	end

	for i,arg in ipairs(argumentos_simples) do
		local argum = args[arg]
		local argnombre = argumentos_nombres[i]
		local argalt = args[arg.."alt"] or {}
		local argtr = args[arg.."tr"] or {}
		local argnum = args[arg.."num"] or {}
		local argnota = args[arg.."nota"] or {}
		
		if arg == "rima" and argum[1] then
			insert(table_markup, "|-\n|'''rima"..(#argum > 1 and "s" or "").."'''\n|[[:Categoría:"..LENG..":Rimas:"..argum[1].."|"..argum[1].."]]".."[[Categoría:"..LENG..":Rimas:"..argum[1].."]]")
			for i=2,#argum do
				insert(table_markup, ", [[:Categoría:"..LENG..":Rimas:"..argum[i].."|"..argum[i].."]]".."[[Categoría:"..LENG..":Rimas:"..argum[i].."]]")
			end
			insert(table_markup, '\n')

		elseif arg == "ac" and argum[1] then
			local t2 = {}
			insert(table_markup, "|-\n|'''acentuación'''\n|")
			local acentuacion_tabla = {
				['m'] = 'monosílaba',
				['a'] = 'aguda',
				['l'] = 'llana',
				['g'] = 'llana',
				['e'] = 'esdrújula',
				['s'] = 'sobreesdrújula',
				['d'] = 'doble',
			}
			
			for i=1,#argum do
				if argum[i] == "mente" then
					argum[i] = "doble"
					generar_error("mente")	
				end
				
				local acento = acentuacion_tabla[argum[i]:sub(1,1)]
				local acento_cat = acento == "doble" and "con 2 sílabas tónicas" or acento.."s"
		
				if acento and sk then
					insert(t2, acento..'[[Categoría:'..LENG..':Palabras '..acento_cat.."|"..sk..']]')
				end
			end
			
			insert(table_markup, concat(t2, ", ").."\n")

		elseif arg == "ls" and argum[1] then
			local t2 = {}
			insert(table_markup, "|-\n|'''longitud silábica'''\n|")
			
			local l_silabica_tabla = {
				[1] = 'monosílaba',
				[2] = 'bisílaba',
				[3] = 'trisílaba',
				[4] = 'tetrasílaba',
				[5] = 'pentasílaba',
				[6] = 'hexasílaba',
				[7] = 'heptasílaba',
				[8] = 'octosílaba',
				[9] = 'eneasílaba',
				[10] = 'decasílaba',
				[11] = 'endecasílaba',
				[12] = 'dodecasílaba',
			}
			
			for i=1,#argum do
				local l_silabica = l_silabica_tabla[argum[i]] or argum[i]
				if sk then
					if type(l_silabica) == 'number' then
						insert(t2, tostring(l_silabica)..'[[Categoría:'..LENG..':Palabras con más de doce sílabas'.."|"..sk..']]')
					else
						insert(t2, l_silabica..'[[Categoría:'..LENG..':Palabras '..l_silabica..'s'..'|'..sk..']]')
					end
				end
			end
			
			insert(table_markup, concat(t2, ", ").."\n")
			
		elseif type(argum) == "string" then
			insert(table_markup, "|-\n|'''"..argnombre.."'''\n|"..argum..'\n')
			
		elseif type(argum) == "table" and #argum > 0 then			
			insert(table_markup, "|-\n|'''"..argnombre.."'''\n|")
			for j,_ in ipairs(argum) do
				local argval = argumentos_links[i] and ("[["..argum[j]..(argalt[j] and "|"..argalt[j] or "").."]]") or argum[j]
				insert(table_markup, (j>1 and ",&nbsp;" or "")..argval..(argtr[j] and " ("..argtr[j]..")" or "")..(argnum[j] and " ("..argnum[j]..")" or "")..(argnota[j] and frame:extensionTag("ref", argnota[j]) or ""))
			end
			insert(table_markup, '\n')
		end
	end

	insert(table_markup, '|}')
	insert(table_markup, require("Módulo:TemplateStyles")("Plantilla:pron-graf/styles.css"))
	return concat(table_markup)
end

function export.mostrar_(frame)

	local params = {
		[1] = {alias_de = "fone"},
		["leng"] = {por_defecto = "es", requerido = true},
		["alt"] = {},
		["ayuda"] = {lista = true},
		["ayudaextra"] = {lista = true},
		["pron"] = {lista_doble = true},
		["fone"] = {lista_doble = true},
		["fono"] = {lista_doble = true},
		["fgraf"] = {lista_doble = true},
		["fnota"] = {lista_doble = true},
		["audio"] = {lista_doble = true},
		["aunota"] = {lista_doble = true},
		["ac"] = {},
		["acentuación"] = {alias_de = "ac"},
		["ls"] = {tipo = "num"},
		["longitud_silábica"] = {alias_de = "ls"},
		["nl"] = {tipo = "num"},
		["número_letras"] = {alias_de = "nl"},
		["d"] = {lista = true},
		["div"] = {alias_de = "d"},
		["división"] = {alias_de = "d"},
		["dnota"] = {lista = true},
		["ts"] = {lista = true},
		["transcripción silábica"] = {alias_de = "ts"},
		["tsnota"] = {lista = true},
		["tl"] = {lista = true},
		["transliteración"] = {alias_de = "tl"},
		["tlalt"] = {lista = true},
		["tlnum"] = {lista = true},
		["tlnúm"] = {alias_de = "tlnum"},
		["tlnota"] = {lista = true},
		["e"] = {lista = true},
		["ea"] = {alias_de = "e"},
		["escritura alternativa"] = {alias_de = "e"},
		["ealt"] = {lista = true},
		["enum"] = {lista = true},
		["enúm"] = {alias_de = "enum"},
		["enota"] = {lista = true},
		["g"] = {lista = true},
		["ga"] = {alias_de = "g"},
		["grafía alternativa"] = {alias_de = "g"},
		["galt"] = {lista = true},
		["gnum"] = {lista = true},
		["gnúm"] = {alias_de = "gnum"},
		["gnota"] = {lista = true},
		["v"] = {lista = true},
		["variante"] = {alias_de = "v"},
		["valt"] = {lista = true},
		["vnum"] = {lista = true},
		["vnúm"] = {alias_de = "vnum"},
		["vtr"] = {lista = true},
		["vnota"] = {lista = true},
		["h"] = {lista = true},
		["homófono"] = {alias_de = "h"},
		["halt"] = {lista = true},
		["hnum"] = {lista = true},
		["hnúm"] = {alias_de = "hnum"},
		["htr"] = {lista = true},
		["hnota"] = {lista = true},
		["p"] = {lista = true},
		["parónimo"] = {alias_de = "p"},
		["palt"] = {lista = true},
		["pnum"] = {lista = true},
		["pnúm"] = {alias_de = "pnum"},
		["ptr"] = {lista = true},
		["pnota"] = {lista = true},
		["s"] = {lista = true},
		["símbolo"] = {alias_de = "s"},
		["salt"] = {lista = true},
		["snum"] = {lista = true},
		["snúm"] = {alias_de = "snum"},
		["snota"] = {lista = true},
		["rima"] = {},
	}
	local parent_frame = frame:getParent()
	local args = require("Módulo:parámetros").obtener_parametros(parent_frame.args, params)
	local title_ = mw.title.getCurrentTitle()
	local title = title_.fullText -- no sirve parent_frame:getTitle()
	local ns = title_.namespace
	local LENG = args["leng"]:upper()
	local leng = args["leng"]
	local idioma, sk
	if ns == 0 then
		idioma = obtener_idioma(leng)
		sk = sortkey(title, leng, idioma)
	end
	--local frame = mw.getCurrentFrame()
	
	if args["pron"][1] and booleano(args["pron"][1][1], true) == false then
		return nil
	end
	
	local items = {"=== Pronunciación y escritura ===\n"}

	if pron_auto[leng] then
		args = require("Módulo:generar-pron/"..leng).procesar_pron_args(title, args)	
	end

	local N = math.max(#args["fone"], #args["fono"])

	if N == 0 then
		insert(items, '<span style="color: green; font-size: 90%; font-style: italic;"> Si puede, agréguela mediante {{pron-graf}}</span>[[Categoría:'..LENG..':Palabras sin transcripción fonética]]\n')
	else
		local tabla = {"{|style='border-spacing: 5px;'"}
		for i = 1,N do
			if args["fone"][i] or args["fono"][i] then
				insert(tabla, '\n|-\n|')
				if args["pron"][i] and args["pron"][i][1] then
					insert(tabla, '[[Wikcionario:Referencia/'..LENG.."/Pronunciación|"..args["pron"][i][1].."]]"..' ([[Alfabeto Fonético Internacional|AFI]])'..': ')
				else
					insert(tabla, '[[Wikcionario:Referencia/'..LENG.."/Pronunciación|Pronunciación]]"..' ([[Alfabeto Fonético Internacional|AFI]])'..': ')
				end
				for j = 1,9 do
					if (args["fone"][i] and args["fone"][i][j]) or (args["fono"][i] and args["fono"][i][j]) then
						if j > 1 then
							insert(tabla, '\n|-\n|')
						end
						local fone_espacio = false
						local graf_espacio = false
						
						insert(tabla, "\n|")
						if args["fgraf"][i] and args["fgraf"][i][j] then
							insert(tabla, "'''"..args["fgraf"][i][j].."''' ")
							graf_espacio = true
						end
						
						insert(tabla, "\n|")
						if args["fone"][i] and args["fone"][i][j] then
							insert(tabla, graf_espacio and ' ['..args["fone"][i][j]..']' or '['..args["fone"][i][j]..']')
							fone_espacio = true
						end
						
						if args["fono"][i] and args["fono"][i][j] then
							insert(tabla, fone_espacio and ' /'..args["fono"][i][j]..'/' or '/'..args["fono"][i][j]..'/')
						end
						
						insert(tabla, "\n|")
						if args["fnota"][i] and args["fnota"][i][j] then
							insert(tabla, ' ('..args["fnota"][i][j]..')')
						end
						
						insert(tabla, "\n|")
						if args["audio"][i] and args["audio"][i][j] then
							if args["aunota"][i] and args["aunota"][i][j] then
								insert(tabla, " "..frame:extensionTag("phonos", frame:extensionTag("small", "''"..args["aunota"][i][j].."''"), {class = "pron-graf", file = args["audio"][i][j], leng = args["leng"]}))
							else
								insert(tabla, " "..frame:extensionTag("phonos", nil, {file = args["audio"][i][j], leng = args["leng"]}))
							end
						end
					end
				end
			end
		end
		if #tabla > 1 then
			insert(items, concat(tabla).."\n|}\n")
		end
	end

	for i,arg in ipairs(argumentos_simples) do
		local argum = args[arg]
		local argnombre = argumentos_nombres[i]
		local argalt = args[arg.."alt"] or {}
		local argtr = args[arg.."tr"] or {}
		local argnum = args[arg.."num"] or {}
		local argnota = args[arg.."nota"] or {}
		
		if arg == "rima" and argum and idioma then
			insert(items, "*Rima: [[:Categoría:"..LENG..":Rimas:"..args["rima"].."|"..args["rima"].."]]".."[[Categoría:"..LENG..":Rimas:"..args["rima"].."]]\n")

		elseif arg == "ac" and argum then
			local acentuacion_tabla = {
				['m'] = 'monosílaba',
				['a'] = 'aguda',
				['l'] = 'llana',
				['g'] = 'llana',
				['e'] = 'esdrújula',
				['s'] = 'sobreesdrújula',
				['d'] = 'doble',
			}
		
			local acento = argum == "mente" and "doble" or acentuacion_tabla[argum:sub(1,1)]
			local acento_cat = acento == "doble" and "con 2 sílabas tónicas" or acento.."s"
			if acento and sk then
				insert(items, "*Acentuación: "..acento..'[[Categoría:'..LENG..':Palabras '..acento_cat.."|"..sk..']]\n')
			end

		elseif arg == "ls" and argum then
			local l_silabica_tabla = {
				[1] = 'monosílaba',
				[2] = 'bisílaba',
				[3] = 'trisílaba',
				[4] = 'tetrasílaba',
				[5] = 'pentasílaba',
				[6] = 'hexasílaba',
				[7] = 'heptasílaba',
				[8] = 'octosílaba',
				[9] = 'eneasílaba',
				[10] = 'decasílaba',
				[11] = 'endecasílaba',
				[12] = 'dodecasílaba',
			}
			local l_silabica = l_silabica_tabla[argum] or argum
			if sk then
				if type(l_silabica) == 'number' then
					insert(items, "*Longitud silábica: "..tostring(l_silabica)..'[[Categoría:'..LENG..':Palabras con más de doce sílabas'.."|"..sk..']]\n')
				else
					insert(items, "*Longitud silábica: "..l_silabica..'[[Categoría:'..LENG..':Palabras '..l_silabica..'s'..'|'..sk..']]\n')
				end
			end
			
			
		elseif type(argum) == "string" then
			insert(items, "*"..argnombre..": "..argum..'\n')
			
		elseif type(argum) == "table" and #argum > 0 then			
			insert(items, "*"..argnombre..": ")
			for j,_ in ipairs(argum) do
				local argval = argumentos_links[i] and ("[["..argum[j]..(argalt[j] and "|"..argalt[j] or "").."]]") or argum[j]
				insert(items, (j>1 and ",&nbsp;" or "")..argval..(argtr[j] and " ("..argtr[j]..")" or "")..(argnum[j] and " ("..argnum[j]..")" or "")..(argnota[j] and frame:extensionTag("ref", argnota[j]) or ""))
			end
			insert(items, '\n')
		end
	end

	--insert(items, '\n')
	--insert(items, require("Módulo:TemplateStyles")("Plantilla:pron-graf/styles.css"))
	return concat(items)
end

return export