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:Langue/Data' )
if success then
dataLangue = resultat
else
-- Base de donnée à 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
-- premierParametre renvoie le premier paramètre de Frame, que celui-ci ait été au module par invoke, directement au modèle,
-- ou à l'intérieur d'un module sous forme de string dans un tableau ou directement de string.
-- Si aucun de ces argument ne contient de chaine, la fonction renvoie nil.
-- Si le deuxième paramètre est true, la chaine est renvoyée trimée et en minuscule.
local function premierParametre( 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
-- Voir Modèle:Direction langue
-- Paramètre :
-- 1 : nom de langue ou code IETF.
function Langue.directionLangue( frame )
local arg = premierParametre( frame, true )
local direction = 'ltr'
local tabLangue = dataLangue[ arg ]
if tabLangue and tabLangue.rtl then
direction = 'rtl'
end
return direction
end
-- Voir Modèle:Code langue
-- Paramètre :
-- 1 : nom de langue.
function Langue.codeLangue( frame )
local arg = premierParametre( frame, true )
local tabLangue = dataLangue[ arg ]
return (tabLangue and tabLangue.code) or arg or ''
end
-- Voir Modèle:Code langue 2
-- Paramètre :
-- 1 : nom de langue.
function Langue.codeLangue2( frame )
local arg = premierParametre( frame, true )
local tabLangue = dataLangue[ arg ]
return (tabLangue and tabLangue.code) or ''
end
-- Voir Modèle:Nom langue
-- Paramètre :
-- 1 : code IETF de langue.
function Langue.nomLangue( frame )
local arg = premierParametre( frame, true )
if type( arg ) ~= 'string' or arg == '' then
return '<span style="color:red">langue non précisée</span>'
end
local tabLangue = dataLangue[ arg ]
if tabLangue then
local nom
if type( tabLangue.page ) == 'string' then
nom = tabLangue.page .. '|' .. tabLangue.nom
else
nom = tabLangue.nom
end
return '[[' .. nom .. ']]'
else
return '<span style="color:red;">langue non reconnue : ' .. arg .. ' </span>'
end
end
-- Voir Modèle:Lang
-- Paramètres :
-- 1 : code IETF de langue,
-- texte ou 2 : texte dans cette langue,
-- trans : translitération du texte,
-- dir : direction de la langue (obsolète : peut être en paramètre 1, avec code en 2 et texte en 3).
function Langue.lang( frame )
local args = ( frame.getParent and frame:getParent().args ) or frame or { } -- préparation pour appel par modèle ou direct.
local code = mw.ustring.lower( mw.text.trim( args[1] or '' ) )
local texte = args.texte or ''
if texte == '' then
texte = args[2] or ''
end
local dir = args.dir
local trans = args.trans
-- Décalage des paramètres si code contient la direction du texte (obsolete mais toujours possible).
if code == 'ltr' or code == 'rtl' then
dir = code
code = mw.ustring.lower( mw.text.trim( args[2] ) )
texte = args[3] or ''
end
-- Si la langue est reconnue, la valeur de la table est prise en compte (permet de corrigé les noms de langue en toute lettre).
local tabLangue = dataLangue[ code ]
if tabLangue and tabLangue.code then
code = tabLangue.code
end
-- Prépatation du rendu de direction du texte.
dir = mw.ustring.lower(dir or '')
if dir == 'ltr' or dir == 'rtl' then
dir = ' dir=' .. dir
else
dir = (tabLangue and tabLangue.rtl and ' dir=rtl') or ''
end
-- Transliteration.
if trans and trans ~= '' then
trans = ' (<span class="lang-' .. code .. ' transcription" lang="' .. code .. '-Latn"'
.. ' dir="ltr">' .. trans .. '</span>)'
else
trans = ''
end
-- Compilation du texte à retourner.
local wikiText = ''
if code == '' then
wikiText = texte
else
wikiText = '<span class="lang-' .. code .. '" lang="' .. code .. '"'
.. dir .. '>' .. texte .. '</span>' .. trans
end
-- Ajout de la catégorie Page avec code de langue invalide si le code langue non reconnu ou invalide.
if success and ( type( tabLangue ) ~= 'table' or tabLangue.invalide ) then
local namespaceCategorisation = { [0] = true, [4] = true, [10] = true, [14] = true, [100] = true }
if namespaceCategorisation[ mw.title.getCurrentTitle().namespace ] then
wikiText = wikiText .. '[[Catégorie:Page avec code de langue invalide|' .. code .. ']]'
end
end
return wikiText
end
-- Voir Modèle:Langue
-- Paramètres :
-- 1 : nom de langue ou code IETF,
-- texte ou 2 : texte dans cette langue,
-- trans : translitération du texte,
-- dir : direction de la langue.
function Langue.langue( frame )
return Langue.lang( frame )
end
-- Voir Modèle:Indication de langue
-- Paramètres :
-- 1 : nom de langue,
-- 2 : code IETF,
-- texte : texte dans cette langue,
-- dir : direction de la langue.
function Langue.indicationDeLangue( frame )
local args = ( frame.getParent and frame:getParent().args ) or frame or { }
local nomLangue = args[1] or ''
local code = args.langue or mw.text.trim( args[2] or '' )
local texte = args.texte
local dir = args.dir
local wikiText = ''
-- Cas ou le premier et/ou le deuxième paramètre est vide.
if code .. nomLangue == '' then
return texte
elseif nomLangue == '' then
nomLangue = dataLangue[ mw.ustring.lower( code ) ]
nomLangue = (nomLangue and nomLangue.nom or '???')
elseif code == '' then
code = dataLangue[ nomLangue ]
code = ( code and code.code or '' )
if code == '' then
return texte
end
end
-- Gestion du texte.
if texte and texte ~= '' then
texte = ' ' .. Langue.lang{ code, dir = dir, texte = texte }
else
texte = ''
end
-- Compilation de l'indicateur de langue et du texte.
wikiText = '<span class="indicateur-langue">(<abbr class="abbr" title="Langue : '
.. nomLangue .. '">'
.. code .. '</abbr>)</span>'
.. texte
return wikiText
end
-- Voir Modèle:Multiling
-- Paramètres : codes IETF ou noms de langue, en nombre indéfini. (string ou nil uniquement)
function Langue.indicationMultilingue( frame )
local args = (frame.getParent and frame:getParent().args) or frame
local listeNom = { }
local listeCode = { }
local tabLangue
-- Valeur par défaut du premier paramètre = 'mul'.
code = mw.ustring.lower( mw.text.trim( args[1] or '' ) )
if code == '' then
code = 'mul'
end
-- Ajout des noms et codes de langue de chaque paramètre dans listeNom et ListeCode.
local i = 1
repeat
tabLangue = dataLangue[ code ]
if type( tabLangue ) == 'table' then
table.insert( listeNom, tabLangue.nom )
table.insert( listeCode, tabLangue.code )
else
table.insert( listeNom, '???' )
local erreur = ' <span style="color:red; font-size:120%;">langue non reconnue : '
.. code .. ' </span>'
table.insert( listeCode, erreur )
end
i = i+1
code = mw.ustring.lower( mw.text.trim( args[i] or '' ) )
until code == ''
-- Préparation et renvoie du texte.
local n = #listeCode
local pluriel = ''
if n == 0 then
return ''
elseif n > 1 then
pluriel = 's'
end
local wikiText = '<span class="indicateur-langue">(<abbr class="abbr" title="Langue' .. pluriel .. ' : '
.. mw.text.listToText( listeNom ) .. '">'
.. table.concat( listeCode, '+' ) .. '</abbr>)</span>'
return wikiText
end
-- Voir Modèle:Langue avec nom
-- Paramètres :
-- 1 : code IETF de langue,
-- texte ou 2 : texte dans cette langue,
-- trans : translitération du texte,
-- dir : direction de la langue.
function Langue.langueAvecNom( frame )
local args = ( frame.getParent and frame:getParent().args ) or frame or { }
local code = mw.ustring.lower( mw.text.trim( args [1] or '') )
local texte = args.texte or args[2] or ''
local trans = args.trans
local dir = args.dir
local wikiText = ''
-- Détection de la direction du texte.
if code == 'ltr' or code == 'rtl' then
dir = code
code = mw.ustring.lower( mw.text.trim( args[2] ) )
texte = args[3] or ''
end
-- Définition du nom de la langue en français.
local nom = Langue.nomLangue{ code }
if texte ~= '' then
texte = ' ' .. Langue.lang{ code, dir = dir, texte = texte, trans = trans }
end
wikiText = nom .. ' :' .. texte
return wikiText
end
-- erreurModuleData affiche d'un message d'erreur si le Module:Langue/Data n'a pas été chargé correctement,
-- pour la page de discussion de la base de donnée et ceux qui veulent surveiller cette page.
function Langue.erreurModuleData()
if success == false then
local message = [[<strong class="error">Le chargement du module Langue/Data génère une erreur : </strong><br />%s<br />
<span class="error">Cette erreur doit être corrigée au plus vite car des milliers de page ne s'affichent pas correctement</span>
]]
return string.format( message, resultat )
end
end
local dataLangue = mw.loadData( 'Module:langue/Data' )
--tableauLangues génère un tableau triable de la liste des langues disponible dans Module:langue/Data.
function Langue.tableauLangues()
if type( dataLangue ) ~= 'table' then
return
end
local tableau = { }
local entete = [[{| class="wikitable alternance sortable"
|-
!scope=col|Alias
!scope=col|code IETF
!scope=col|Nom principal
!scope=col|Page
!scope=col|RTL
!scope=col|invalide]]
local lignetab, lignesrt
for i, v in pairs( dataLangue ) do
lignetab = {
i,
v.code,
v.nom,
v.page or '',
v.rtl and '[[Image:Yes check.svg|15px|oui|lien=]]' or '',
v.invalide and '[[Image:Yes check.svg|15px|oui|lien=]]' or '',
}
lignesrt = table.concat( lignetab, '\n|' )
table.insert( tableau, lignesrt )
end
table.sort( tableau )
table.insert( tableau, 1, entete )
table.insert( tableau, '}' )
return table.concat( tableau, '\n|-\n|' )
end
-- copie de premierParametre pour la 2e langue
local function secondParametre( 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 codeLangue1 = args[1] or ''
local codeLangue2 = args[4] or ''
local nomArticle1 = args[2] or ''
local nomArticle2 = args[5] or ''
local oldId1 = args[3] or ''
local oldId2 = args[6] or ''
-- teste si les oldId sont nuls ou ont une longueur différente de 9 chiffres.
local erreurId = 0
if nomArticle2 == '' then
if oldId1 == '' or string.len( oldId1 ) ~= 9 then
erreurId = 1
end
else
if oldId1 == '' or string.len( oldId1 ) ~= 9 then
erreurId = 1
end
if oldId2 == '' or string.len( oldId1 ) ~= 9 then
erreurId = 1
end
end
if erreurId == 1 then
return '<span style="color:red;">Erreur dans {{m|Traduction/Référence}} : oldid invalide.</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 = premierParametre( frame, true )
-- if type( arg ) ~= 'string' or arg == '' then
-- return '<span style="color:red">Erreur dans {{m|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 {{m|Traduction/Référence}} : langue non reconnue : ' .. arg .. '.</span> [[Catégorie:Page avec code de langue invalide]]'
end
-- 2e langue
if nomArticle2 ~= '' then
local arg2 = secondParametre( frame, true )
if type( arg2 ) ~= 'string' or arg2 == '' then
return '<span style="color:red">Erreur dans {{m|Traduction/Référence}} : 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 {{m|Traduction/Référence}} : langue non reconnue : ' .. arg .. '.</span> [[Catégorie:Page avec code de langue invalide]]'
end
end
-- compilation du texte
if nomArticle2 == ''
then
local wikitext = '* <span class="indicateur-langue">(<abbr class="abbr" title="Langue : '
.. nom1 .. '">'
.. codeLangue1 .. '</abbr>)</span> Cet article est partiellement ou en totalité issu de l’article de Wikipédia en [['
.. nom1 .. ']] intitulé « [https://en.wikipedia.org/wiki/'
.. mw.uri.encode( nomArticle1 , "WIKI" ) .. '?oldid='
.. oldId1 .. ' '
.. nomArticle1 ..'] » (voir la [https://en.wikipedia.org/wiki/'
.. mw.uri.encode( nomArticle1 , "WIKI" ) .. '?action=history liste des auteurs])'
return wikitext
else
local wikitext = '* <span class="indicateur-langue">(<abbr class="abbr" title="Langue : '
.. nom1 .. '">'
.. codeLangue1 .. '</abbr>)</span> Cet article est partiellement ou en totalité issu de l’article de Wikipédia en [['
.. nom1 .. ']] intitulé « [https://en.wikipedia.org/wiki/'
.. mw.uri.encode( nomArticle1 , "WIKI" ) .. '?oldid='
.. oldId1 .. ' '
.. nomArticle1 ..'] » (voir la [https://en.wikipedia.org/wiki/'
.. mw.uri.encode( nomArticle1 , "WIKI" ) .. '?action=history liste des auteurs])\n* <span class="indicateur-langue">(<abbr class="abbr" title="Langue : '
.. nom2 .. '">'
.. codeLangue2 .. '</abbr>)</span> Cet article est partiellement ou en totalité issu de l’article de Wikipédia en [['
.. nom2 .. ']] intitulé « [https://en.wikipedia.org/wiki/'
.. mw.uri.encode( nomArticle2 , "WIKI" ) .. '?oldid='
.. oldId1 .. ' '
.. nomArticle2 ..'] » (voir la [https://en.wikipedia.org/wiki/'
.. mw.uri.encode( nomArticle2 , "WIKI" ) .. '?action=history liste des auteurs])'
return wikitext
end
end
return Langue