Módulo:lengua
Ir a la navegación
Ir a la búsqueda
La documentación para este módulo puede ser creada en Módulo:lengua/doc
local p = {}
local lang = mw.language.new( 'es' )
p.main = function( frame )
local pframe = frame:getParent()
if not pframe.args[ 1 ] then
error( 'parámetro obligatorio: código de idioma (p. ej. "es")' )
end
local code = pframe.args[ 1 ]
local ucode = string.upper( code )
local lcode = string.lower( code )
local is_transliteration = false
local writing_names = {}
local writing_categories = {}
local function check_writing( parameter )
local category = parameter
if parameter == 'transliteración' then
is_transliteration = true
category = 'transliteraciones'
end
local category_link = mw.ustring.format( '[[Categoría:%s:%s]]', ucode, lang:ucfirst( category ) )
table.insert( writing_names, parameter )
table.insert( writing_categories, category_link )
end
if pframe.args[ 'escritura' ] then check_writing( pframe.args[ 'escritura' ] ) end
if pframe.args[ 'escritura2' ] then check_writing( pframe.args[ 'escritura2' ] ) end
if pframe.args[ 'escritura3' ] then check_writing( pframe.args[ 'escritura3' ] ) end
local span = mw.html.create( 'span' )
:attr( 'id', lcode )
:addClass( 'headline-lang' )
local reference_page = mw.title.new( 'Wikcionario:Referencia/' .. ucode )
local lang = lang:ucfirst( frame:expandTemplate{ title = 'getlang', args = { lcode } } )
local header
if reference_page.exists then
header = mw.ustring.format( '[[%s|%s]]', reference_page.fullText, lang )
else
header = lang
end
if #writing_names > 0 then
local small = mw.html.create( 'small' )
:wikitext( '(' .. table.concat( writing_names, ', ' ) .. ')' )
header = header .. ' ' .. tostring( small )
end
local out = tostring( span:wikitext( header ) )
if mw.title.getCurrentTitle().namespace == 0 then
if not is_transliteration then
local category_name
if lcode == 'es' then
category_name = 'Español'
else
category_name = mw.ustring.format( '%s-Español', lang )
end
out = out .. mw.ustring.format( '[[Categoría:%s]]', category_name )
end
if #writing_categories > 0 then
out = out .. table.concat( writing_categories )
end
end
return out
end
return p