Module:Utilisateur:SyntaxTerror
Apparence
[voir] [modifier] [historique] [purger]
Utilisateur:SyntaxTerror/Brouillon/Module
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ée des langues avec gestion d'erreur.
local dataLangue
local success, resultat = pcall (mw.loadData, 'Module:Utilisateur:SyntaxTerror/Data' )
if success then
dataLangue = resultat
else
-- Base de donnée à minima en cas de bug sur le Module:Utilisateur:SyntaxTerror/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
local function param1( frame, lowerCase )
local arg
if type( frame ) == 'table' then
arg = ( frame.getParent and ( frame.args[1] or frame:getParent().args[1] ) ) or frame[1]
elseif type( frame ) == 'string' then
arg = frame
end
if type( arg ) ~= 'string' then
arg = nil
end
if arg and lowerCase then
arg = mw.ustring.lower( mw.text.trim ( arg ) )
end
return arg
end
-- copie de premierParametre pour la 2e langue
local function param2( frame, lowerCase )
local arg
if type( frame ) == 'table' then
arg = ( frame.getParent and ( frame.args[4] or frame:getParent().args[4] ) ) or frame[4]
elseif type( frame ) == 'string' then
arg = frame
end
if type( arg ) ~= 'string' then
arg = nil
end
if arg and lowerCase then
arg = mw.ustring.lower( mw.text.trim ( arg ) )
end
return arg
end
-- Voir Modèle:Traduction/Référence (bientôt ;p)
-- Paramètres :
-- 1 ou lang1 : code IETF de langue,
-- 2 ou art1 : nom de l'article,
-- 3 ou id1 : oldid de l'article
-- 4 lang2 : code IETF de langue (2e article),
-- 5 ou art2 : nom de l'article (2e article),
-- 6 ou id2 : oldid de l'article (2e article).
function Langue.traductionReference(frame)
local args = ( frame.getParent and frame:getParent().args ) or frame or { }
local lang1 = args[1] or args["lang1"]
if lang1 == nil 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
local lang2 = args[4] or args["lang2"]
if lang2 == nil then
return '<span style="color:red">Erreur dans {{Traduction/Référence}} : 2e langue non précisée.</span> [[Catégorie:Page avec code de langue invalide]]'
end
local art1 = args[2] or args["art1"]
if art1 == nil then
return '<span style="color:red">Erreur dans {{Traduction/Référence}} : nom d’article manquant.</span>'
end
local art2 = args[5] or args["art2"]
if art2 == nil then
return '<span style="color:red">Erreur dans {{Traduction/Référence}} : nom du 2e article manquant.</span>'
end
local id1 = args[3] or args["id1"]
if id1 == nil then
return '<span style="color:red;">Erreur dans {{m|Traduction/Référence}} : oldid manquant.</span> [[Catégorie:Page avec un oldid invalide|Reference]]'
end
local id2 = args[6] or args["id1"]
if id2 == nil then
return '<span style="color:red;">Erreur dans {{m|Traduction/Référence}} : 2e oldid manquant.</span> [[Catégorie:Page avec un oldid invalide|Reference]]'
end
--donne les noms de langue selon les codes et renvoie des erreurs s'ils sont absents ou erronés.
-- 1re langue
local arg = param1( frame, true )
if type( arg ) ~= 'string' or arg == '' 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
local tabLangue = dataLangue[ arg ]
local nom1
if tabLangue then
if type( tabLangue.page ) == 'string' then
nom1 = tabLangue.page .. '|' .. tabLangue.nom
else
nom1 = tabLangue.nom
end
else
return '<span style="color:red;">Erreur dans {{Traduction/Référence}} : langue non reconnue : ' .. arg .. '.</span> [[Catégorie:Page avec code de langue invalide]]'
end
-- 2e langue
local arg = param2( frame, true )
if type( arg ) ~= 'string' or arg == '' then
return '<span style="color:red">Erreur dans {{Traduction/Référence}} : 2e langue non précisée. </span> [[Catégorie:Page avec code de langue invalide]]'
end
local tabLangue = dataLangue[ arg2 ]
local nom2
if tabLangue then
if type( tabLangue.page ) == 'string' then
nom2 = tabLangue.page .. '|' .. tabLangue.nom
else
nom2 = tabLangue.nom
end
else
return '<span style="color:red;">Erreur dans {{Traduction/Référence}} : 2e langue non reconnue : ' .. arg .. '.</span> [[Catégorie:Page avec code de langue invalide]]'
end
-- compilation du texte
if art2 == '' then
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>)'
return wikitext
else
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>)\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>)'
return wikitext
end
end
return Langue