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 'XXX'
local art1 = args[2] or args["art1"] or 'XXX'
local id1 = args[3] or args["id1"] or 'XXX'
local lang2 = args[4] or args["lang2"] or 'XXX'
local art2 = args[5] or args["art2"] or 'XXX'
local id2 = args[6] or args["id2"] or 'XXX'
local nom1 = 'X+X'
local nom2 = 'X+X'
-- 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. </span> [[Catégorie:Page avec code de langue invalide]]'
end
if lang2 == '' then
return '<span style="color:red"> Erreur dans {{Traduction/Référence}} : langue non précisée. </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 : ' .. lang1 .. ' </span>[[Catégorie:Page avec code de langue invalide]]'
end
if tabLangue2 then
if type( tabLangue2.page ) == 'string' then
nom1 = tabLangue2.page .. '|' .. tabLangue2.nom
else
nom1 = tabLangue2.nom
end
else
return '<span style="color:red;"> Erreur dans {{Traduction/Référence}} : langue non reconnue : ' .. lang2 .. ' </span>[[Catégorie:Page avec code de langue invalide]]'
end
-- texte à renvoyer
local wikitext = '* <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/'
.. mw.uri.encode( art1 , "WIKI" ) .. '?oldid='
.. id1 .. ' '
.. art1 ..']</span> » (voir la <span class="plainlinks">[https://en.wikipedia.org/wiki/'
.. mw.uri.encode( art1 , "WIKI" ) .. '?action=history liste des auteurs]</span>)'
if art2 ~= 'XXX' then
wikitext = '* <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/'
.. mw.uri.encode( art1 , "WIKI" ) .. '?oldid='
.. id1 .. ' '
.. art1 ..']</span> » (voir la <span class="plainlinks">[https://en.wikipedia.org/wiki/'
.. mw.uri.encode( art1 , "WIKI" ) .. '?action=history liste des auteurs]</span>)\n* <span class="indicateur-langue">(<abbr class="abbr" title="Langue : '
.. nom2 .. '">'
.. lang2 .. '</abbr>)</span> Cet article est partiellement ou en totalité issu de l’article de Wikipédia en [['
.. nom2 .. ']] intitulé « <span class="plainlinks">[https://'
.. lang2 .. '.wikipedia.org/wiki/'
.. mw.uri.encode( art2 , "WIKI" ) .. '?oldid='
.. id2 .. ' '
.. art2 ..']</span> » (voir la <span class="plainlinks">[https://en.wikipedia.org/wiki/'
.. mw.uri.encode( art2 , "WIKI" ) .. '?action=history liste des auteurs]</span>)'
end
return wikitext
end
return Langue
--[=[
Utilisateur:SyntaxTerror/Brouillon/Module2
wikitexte = '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>.'
]=]