local p = {}
local ModuloArgumentos = require('Módulo:Argumentos')
local ModuloFicha = require('Módulo:Ficha')
local ModuloWikidata = require('Module:Wikidata')
local ModuloPaginas = require('Módulo:Páginas')
local argumentos
local Entidad
function p.Ficha(frame)
argumentos = ModuloArgumentos.obtenerArgumentosConValor(frame)
Entidad = mw.wikibase.getEntityObject(argumentos.id) or {}
local Titulo = argumentos['título'] or obtenerEtiquetaWikidata() or ModuloPaginas.nombrePagina({desambiguar='sí'})
-- Propiedades
local Simbolo1 = argumentos['símbolo']
local Simbolo2 = argumentos['símbolo2']
local Simbolo3 = argumentos['símbolo3']
local Simbolo4 = argumentos['símbolo4']
local Simbolo
local tmp
local tmp2
if Simbolo1 then
Simbolo = Simbolo1
if Simbolo2 then
Simbolo = Simbolo .. ', ' .. Simbolo2
if Simbolo3 then
Simbolo = Simbolo .. ', ' .. Simbolo3
if Simbolo4 then
Simbolo = Simbolo .. ', ' .. Simbolo4
end
end
end
elseif propiedad('P898') then
Simbolo = propiedad('P898', {['linkback']='sí', ['conjunción']=', '})
else
Simbolo = ''
end
local AFI = argumentos['número afi'] or propiedad('P3917') or ''
if argumentos['decimal'] then
tmp = '&#' .. argumentos['decimal'] .. ';'
if argumentos['decimal2'] then
tmp = tmp .. ', &#' .. argumentos['decimal2'] .. ';'
end
end
local HTML = tmp or getHTMLEntity(propiedad('P898', {['linkback']='sí', ['conjunción']=', '})) or ''
if argumentos['unicode'] then
tmp = 'U+'.. argumentos['unicode']
if argumentos['unicode2'] then
tmp = tmp .. ', U+' .. argumentos['unicode2']
end
else
tmp = nil
end
local Unicode = tmp or getUnicodeCode(propiedad('P898', {['linkback']='sí', ['conjunción']=', '})) or ''
if argumentos['xsampa'] then
tmp = argumentos['xsampa']
if argumentos['xsampa2'] then
tmp = tmp .. argumentos['xsampa2']
if argumentos['xsampa3'] then
tmp = tmp .. argumentos['xsampa3']
if argumentos['xsampa4'] then
tmp = tmp .. argumentos['xsampa4']
end
end
end
else
tmp = nil
end
local XSAMPA = tmp or propiedad('P2859') or ''
local Kirshenbaum = argumentos['kirshenbaum'] or propiedad('P3625') or ''
local RFE = argumentos['rfe'] or ''
local Braille
if argumentos['braille'] then
tmp2 = "[[File:" .. argumentos['braille'] .. "|25px]]"
tmp = tmp2
if argumentos['braille2'] then
tmp2 = "[[File:" .. argumentos['braille2'] .. "|25px]]"
tmp = tmp .. tmp2
if argumentos['braille3'] then
tmp2 = "[[File:" .. argumentos['braille3'] .. "|25px]]"
tmp = tmp .. tmp2
if argumentos['braille4'] then
tmp2 = "[[File:" .. argumentos['braille4'] .. "|25px]]"
tmp = tmp .. tmp2
end
end
end
Braille = tmp
elseif propiedad('P4225') then
Braille = '<span style="font-size: 2em; padding: .3em">' .. propiedad('P4225') .. '</span>'
else
Braille = ''
end
local Nota1
local Nota2
local Nota3
if argumentos['nota1'] then
Nota1 = '* ' .. argumentos['nota1']
else
Nota1 = ''
end
if argumentos['nota2'] then
Nota2 = '* ' .. argumentos['nota2']
else
Nota2 = ''
end
if argumentos['nota3'] then
Nota3 = '* ' .. argumentos['nota3']
else
Nota3 = ''
end
local Sonido = argumentos['sonido'] or propiedad('P51', {['linkback'] = 'no'})
if Sonido then
Sonido = frame:preprocess('{{multimedia|archivo='.. Sonido ..'|título=Pronunciación|simple=sí}}')
else
Sonido = ''
end
local FichaCodigo = {
entidad = argumentos.id,
titulo = capitalizar(Titulo),
subtitulo = Simbolo,
estilosubtitulo = 'text-align:center;background:#fff;font-size:2rem;padding-top:.75rem;height:2rem',
clasetitulo = 'cabecera',
estilotitulo = 'background-color: #ccccff; color:#000',
estiloseccion = 'background-color: #ccccff; color:#000',
estiloetiqueta = 'background-color: #ddddff; width:65%',
{tipo='sección',
titulo = "Codificación",
{'[[Alfabeto Fonético Internacional#Letras|Orden en el <abbr title="Alfabeto Fonético Internacional">AFI<abbr>]]', AFI},
{'Entidad <abbr title="HyperText Markup Language">HTML</abbr> <abbr style="font-size:85%" title="decimal">(dec)</abbr>', HTML},
{'[[Unicode]] <abbr style="font-size:85%" title="hexadecimal">(hex)</abbr>', Unicode},
{'[[X-SAMPA]]', XSAMPA},
{'[[Kirshenbaum]]', Kirshenbaum},
{'[[Revista de Filología Española|RFE]]', RFE},
{'[[Braille AFI|Braille]]', Braille},
},
{tipo='sección',
titulo = "Notas",
{'', Nota1},
{'', Nota2},
{'', Nota3},
},
{tipo='sección',
titulo = "Sonido",
{'', Sonido},
}
}
return ModuloFicha.infobox(FichaCodigo)
end
function obtenerEtiquetaWikidata()
if Entidad and Entidad.labels and Entidad.labels.es then
return Entidad.labels.es.value
end
end
function propiedad(idPropiedad,opciones)
if Entidad and Entidad.claims and Entidad.claims[idPropiedad] then
if not opciones then
opciones = {['linkback']='sí'}
end
opciones.entityId = Entidad.id
opciones.propiedad = idPropiedad
valorPropiedad = ModuloWikidata.getPropiedad(opciones,Entidad.claims[idPropiedad])
return valorPropiedad
end
end
function decToHex(num)
local B,K,res,I,D=16,"0123456789ABCDEF","",0
while num>0 do
I=I+1
num,D=math.floor(num/B),math.mod(num,B)+1
res=string.sub(K,D,D)..res
end
return res
end
function getHTMLEntity(prop)
if mw.ustring.isutf8(prop) then
return mw.text.encode('&#' .. mw.ustring.codepoint(prop) .. ';')
end
end
function getUnicodeCode(prop)
if mw.ustring.isutf8(prop) then
local Codepoint = decToHex(mw.ustring.codepoint(prop))
local Coletilla
if mw.ustring.len(Codepoint) == 4 then
Coletilla = 'U+'
elseif mw.ustring.len(Codepoint) == 3 then
Coletilla = 'U+0'
elseif mw.ustring.len(Codepoint) == 2 then
Coletilla = 'U+00'
elseif mw.ustring.len(Codepoint) == 1 then
Coletilla = 'U+000'
else
Coletilla = 'U+'
end
return Coletilla .. Codepoint
end
end
function capitalizar(cad)
return string.upper(string.sub(cad,1,1)) .. string.sub(cad,2)
end
return p