Módulo:lengua
La documentación para este módulo puede ser creada en Módulo:lengua/doc
local p = {}
local generar_error = require("Módulo:traza")
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 ]
if code:find("[^a-z-]") then
generar_error("cod")
end
local ucode = string.upper( code )
local lcode = string.lower( code )
local ucfirst = require("Módulo:String").ucfirst
local lang = ucfirst(require('Módulo:lenguas').cod_a_nombre(lcode))
local is_transliteration = false
local writing_names = {}
local writing_categories = {}
local function check_writing( parameter )
local category = parameter
if parameter == 'transliteración' then
generar_error("translit")
is_transliteration = true
category = 'transliteraciones'
end
local category_link = mw.ustring.format( '[[Categoría:%s:%s]]', ucode, 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 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
out = out .. mw.ustring.format( '[[Categoría:%s]]', lang )
end
if #writing_categories > 0 then
out = out .. table.concat( writing_categories )
end
end
return out
end
return p