Module:Utilisateur:SyntaxTerror/2
Apparence
[voir] [modifier] [historique] [purger]
La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis sa sous-page de documentation. Veuillez placer les catégories sur cette page-là.
Les éditeurs peuvent travailler dans le bac à sable (créer).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
local Langue = { }
-- Chargement du de la base de données des langues avec gestion d'erreur.
local dataLangue
local success, resultat = pcall (mw.loadData, 'Module:Langue/Data' )
if success then
dataLangue = resultat
else
-- Base de données à minima en cas de bug sur le Module:Langue/Data
dataLangue = { en = { code = 'en', nom = anglais },
de = { code = 'de', nom = 'allemand' },
it = { code = 'it', nom = 'italien' },
es = { code = 'es', nom = 'espagnol' }, }
dataLangue.anglais = dataLangue.en
dataLangue.allemand = dataLangue.de
dataLangue.italien = dataLangue.it
dataLangue.espagnol = dataLangue.es
end
-- traductionReference
function Langue.traductionReference(frame)
local args = ( frame.getParent and frame:getParent().args ) or frame or { }
local lang1 = args[1] or args["lang1"] or ''
local art1 = args[2] or args["art1"] or ''
local id1 = args[3] or args["id1"] or ''
local lang2 = args[4] or args["lang2"] or ''
local art2 = args[5] or args["art2"] or ''
local id2 = args[6] or args["id2"] or ''
local nom1 = 'X+X'
local nom2 = 'X+X'
if lang2 == nil then
lang2 = ''
end
if art2 == nil then
art2 = ''
end
if id2 == nil then
id2 = ''
end
-- massages d'erreur en cas de paramètres manquants
if lang1 == '' then
return '<span style="color:red"> Erreur dans {{Traduction/Référence}} : langue non précisée. (1) </span> [[Catégorie:Page avec code de langue invalide]]'
end
if lang2 == '' and art2 ~= '' then
return '<span style="color:red"> Erreur dans {{Traduction/Référence}} : langue non précisée. (2) </span> [[Catégorie:Page avec code de langue invalide]]'
end
-- définition du nom de la langue et de son code d'indication de langue (qui peut être différent du code wikipédia)
local code1 = mw.ustring.lower( mw.text.trim( lang1 ) )
local code2 = mw.ustring.lower( mw.text.trim( lang2 ) )
local tabLangue1 = dataLangue[ code1 ]
local tabLangue2 = dataLangue[ code2 ]
local nom1 = ''
local nom2 = ''
if tabLangue1 then
if type( tabLangue1.page ) == 'string' then
nom1 = tabLangue1.page .. '|' .. tabLangue1.nom
else
nom1 = tabLangue1.nom
end
else
return '<span style="color:red;"> Erreur dans {{Traduction/Référence}} : langue non reconnue : (3)' .. lang1 .. ' </span>[[Catégorie:Page avec code de langue invalide]]'
end
if tabLangue2 and art2 then
if type( tabLangue2.page ) == 'string' then
nom2 = tabLangue2.page .. '|' .. tabLangue2.nom
else
nom2 = tabLangue2.nom
end
-- else
-- return '<span style="color:red;"> Erreur dans {{Traduction/Référence}} : langue non reconnue : (4)' .. lang2 .. ' </span>[[Catégorie:Page avec code de langue invalide]]'
end
-- table contenant le texte à renvoyer pour la 1re langue
local text1 = {}
local text2 = {}
local encode1 = mw.uri.encode( art1 , "WIKI" )
text1 = { '* <span class="indicateur-langue">(<abbr class="abbr" title="Langue : ',
nom1,
'">',
lang1,
'</abbr>)</span> Cet article est partiellement ou en totalité issu de l’article de Wikipédia en [[' ,
nom1,
']] intitulé « <span class="plainlinks">[https://',
lang1,
'.wikipedia.org/wiki/',
encode1,
'?oldid=',
id1,
' ',
art1,
']</span> » (voir la <span class="plainlinks">[https://',
lang1,
'.wikipedia.org/wiki/',
encode1,
'?action=history liste des auteurs]</span>)' }
-- copie de la table text1 avec ajout des paramètres pour la 2e langue
local text2 = mw.clone( text1 )
local encode2 = mw.uri.encode( art2 , "WIKI" )
text2 [1] = '\n* <span class="indicateur-langue">(<abbr class="abbr" title="Langue : '
text2 [2] = nom2
text2 [4] = lang2
text2 [6] = nom2
text2 [8] = lang2
text2 [10] = encode2
text2 [12] = id2
text2 [14] = art2
text2 [16] = lang2
text2 [18] = encode2
--concaténation des tables
local wikitext = table.concat( text1 ) .. table.concat( text2 )
return wikitext
end
return Langue
--[=[
wikitext = 'lang1 = <span style="color:green;">' .. lang1 ..
'</span>, art1 = <span style="color:green;">' .. art1 ..
'</span>, id1 = <span style="color:green;">' .. id1 ..
'</span>, lang2 = <span style="color:green;">' .. lang2 ..
'</span>, art2 = <span style="color:green;">' .. art2 ..
'</span>, id2 = <span style="color:green;">' .. id2 ..
'</span>.'
]=]
--[=[
Utilisateur:SyntaxTerror/Brouillon/Module2
]=]