Bienvenue sur le wiki de Nuit debout, nous sommes le 2990 mars.




Module:Langue : Différence entre versions

De NuitDebout
Aller à : navigation, rechercher
(Ajout de listeCodeAlias, pour générer une liste des codes de langues supportés, Sous forme de liste et non de tableau)
(si "page" est une chaîne vide, ne pas créer de lien ; utilisé par les codes "mis", "und" et "zxx")
 
(32 révisions intermédiaires par 8 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
 
local Langue = { }
 
local Langue = { }
  
-- Chargement du de la base de donnée des langues avec gestion d'erreur.
+
-- Chargement de la base de données des langues avec gestion d'erreur.
 
local dataLangue
 
local dataLangue
local success, resultat = pcall (mw.loadData, 'Module:Langue/Data' )
+
local moduleData = 'Module:Langue/Data'
 +
local langErrorMess = '<span class=error>langue non reconnue : %s</span>'
 +
local success, resultat = pcall (mw.loadData, moduleData )
 +
success = success and type( resultat.en ) == 'table'
 
if success then
 
if success then
    dataLangue = resultat
+
dataLangue = resultat
 
else
 
else
    -- Base de donnée à minima en cas de bug sur le Module:Langue/Data
+
-- Base de données a minima en cas de bug sur le Module:Langue/Data
    dataLangue = { en = { code = 'en', nom = anglais },  
+
dataLangue = { en = { code = 'en', nom = anglais },
        de = { code = 'de', nom = 'allemand' },  
+
fr = { code = 'fr', nom = 'français' },
        it = { code = 'it', nom = 'italien' },  
+
de = { code = 'de', nom = 'allemand' },
        es = { code = 'es', nom = 'espagnol' }, }
+
es = { code = 'es', nom = 'espagnol' },
    dataLangue.anglais = dataLangue.en
+
it = { code = 'it', nom = 'italien' },
    dataLangue.allemand = dataLangue.de
+
la = { code = 'la', nom = 'latin'   },
    dataLangue.italien = dataLangue.it
+
['rtl script'] = { Arab = true }
    dataLangue.espagnol = dataLangue.es
+
}
 +
dataLangue.anglais = dataLangue.en
 +
dataLangue['français'] = dataLangue.fr
 +
dataLangue.allemand = dataLangue.de
 +
dataLangue.espagnol = dataLangue.es
 +
dataLangue.italien = dataLangue.it
 
end
 
end
  
-- premierParametre renvoie le premier paramètre de Frame, que celui-ci ait été au module par invoke, directement au modèle,  
+
-- premierParametre renvoie le premier paramètre de Frame, que celui-ci ait été passé 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.
 
-- 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 aucun de ces arguments 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.
+
-- Si le deuxième paramètre est true, la chaine est renvoyée trimée et en minuscules.
 
local function premierParametre( frame, lowerCase )
 
local function premierParametre( frame, lowerCase )
    local arg
+
local arg
    if type( frame ) == 'table' then
+
if type( frame ) == 'table' then
        arg = ( frame.getParent and ( frame.args[1] or frame:getParent().args[1] ) ) or frame[1]
+
arg = ( frame.getParent and ( frame.args[1] or frame:getParent().args[1] ) ) or frame[1]
    elseif type( frame ) == 'string' then
+
elseif type( frame ) == 'string' then
        arg = frame
+
arg = frame
    end
+
end
    if type( arg ) ~= 'string' then
+
if type( arg ) ~= 'string' then
        arg = nil
+
arg = nil
    end
+
end
    if arg and lowerCase then
+
if arg and lowerCase then
        arg = mw.ustring.lower( mw.text.trim ( arg ) )
+
arg = mw.ustring.lower( mw.text.trim ( arg ) )
    end
+
end
    return arg
+
return arg
 
end
 
end
  
-- Voir Modèle:Direction langue
+
-- determinationCode retourne une table contenant le code de langue principal et la liste des subcode
-- Paramètre :
+
-- si le code de langue principal n'est pas reconnu, retourne nil.
--    1  : nom de langue ou code IETF.
+
function Langue.determinationCode( langue )
function Langue.directionLangue( frame )
+
if type( langue ) == 'string' and langue ~= '' then
    local arg = premierParametre( frame, true )
+
local tabCode = mw.text.split( langue, '-' )
    if type( arg ) ~= 'string' or arg == '' then
+
local tabLangue = dataLangue[ mw.ustring.lower( tabCode[1] ) ]
        return 'ltr'
+
if tabLangue and tabLangue.code then
    end
+
tabCode[1] = tabLangue.code
    local tabLangue = dataLangue[ arg ]
+
if tabLangue.invalide then
    if tabLangue and tabLangue.rtl then
+
tabCode.invalide=true
        return 'rtl'
+
end
    elseif tabLangue == nil then
+
return tabCode
        -- si la langue n'es pas directement dans la base, on essai avec les subtag
+
end
        local codeMain, codeSub = mw.ustring.match( arg, '^(%a-)%-(.+)$' )
+
end
        if codeSub then
+
            if string.len(codeSub) == 4 and dataLangue[ 'rtl script' ] then
+
                -- codeSub est un code de script, on compare au script rtl
+
                codeSub = string.upper( string.sub( codeSub, 1, 1 ) ) .. string.sub( codeSub, 2 )
+
                if dataLangue[ 'rtl script' ][ codeSub ] then
+
                    return 'rtl'
+
                end
+
            else
+
                -- sinon on utilise le code principal et on teste s'il est présent dans la base.
+
                tabLangue = dataLangue[ codeMain ]
+
                if tabLangue and tabLangue.rtl then
+
                    return 'rtl'
+
                end
+
            end
+
        end
+
    end
+
    return 'ltr'
+
 
end
 
end
  
 
-- Voir Modèle:Code langue
 
-- Voir Modèle:Code langue
-- Paramètre :  
+
-- Paramètre :
 
--    1  : nom de langue.
 
--    1  : nom de langue.
 
function Langue.codeLangue( frame )
 
function Langue.codeLangue( frame )
    local arg = premierParametre( frame, true )
+
local arg = premierParametre( frame, true )
    local tabLangue = dataLangue[ arg ]
+
local tabCode = Langue.determinationCode( arg )
    return (tabLangue and tabLangue.code) or arg or ''
+
return ( tabCode and table.concat( tabCode, '-' ) ) or arg or ''
 
end
 
end
  
 
-- Voir Modèle:Code langue 2
 
-- Voir Modèle:Code langue 2
-- Paramètre :  
+
-- Paramètre :
 
--    1  : nom de langue.
 
--    1  : nom de langue.
 
function Langue.codeLangue2( frame )
 
function Langue.codeLangue2( frame )
    local arg = premierParametre( frame, true )
+
local arg = premierParametre( frame, true )
    local tabLangue = dataLangue[ arg ]
+
local tabCode = Langue.determinationCode( arg )
    return (tabLangue and tabLangue.code) or ''
+
return ( tabCode and table.concat( tabCode, '-' ) ) or ''
 
end
 
end
 +
 +
 +
-- Voir Modèle:Direction langue
 +
-- Paramètre :
 +
--    1  : nom de langue ou code IETF.
 +
function Langue.directionLangue( frame )
 +
local arg = premierParametre( frame, true )
 +
if type( arg ) ~= 'string' or arg == '' then
 +
return 'ltr'
 +
end
 +
-- séparation du code de langue en code principal et les différents subcode.
 +
local tabCode = Langue.determinationCode( arg )
 +
if tabCode then
 +
-- on essaye de savoir si la direction est de droite à gauche
 +
local codeScript = tabCode[2]
 +
if codeScript and string.len( codeScript ) == 4 and dataLangue[ 'rtl script' ] then
 +
-- il y a un subcode d'écritrure, c'est lui qui est pris en compte
 +
codeScript = string.upper( string.sub( codeScript, 1, 1 ) ) .. string.sub( codeScript, 2 )
 +
if dataLangue[ 'rtl script' ][ codeScript ] then
 +
return 'rtl'
 +
end
 +
else
 +
-- il n'y a pas de sub-code d'écriture, on prend en compte le code de langue principal.
 +
local tabLangue = dataLangue[ tabCode[1] ]
 +
if tabLangue and tabLangue.rtl then
 +
return 'rtl'
 +
end
 +
end
 +
end
 +
 +
-- la langue n'est pas écrite de droite à gauche, donc ltr.
 +
return 'ltr'
 +
end
 +
  
 
-- Voir Modèle:Nom langue
 
-- Voir Modèle:Nom langue
-- Paramètre :  
+
-- Paramètre :
 
--    1  : code IETF de langue.
 
--    1  : code IETF de langue.
 
function Langue.nomLangue( frame )
 
function Langue.nomLangue( frame )
    local arg = premierParametre( frame, true )
+
local arg = premierParametre( frame, true )
    if type( arg ) ~= 'string' or arg == '' then  
+
if type( arg ) ~= 'string' or arg == '' then
        return '<span style="color:red">langue non précisée</span>'
+
return '<span class=error>langue non précisée</span>'
    end
+
end
    local tabLangue = dataLangue[ arg ]
+
local tabLangue = dataLangue[ arg ]
    if tabLangue == nil then
+
if tabLangue == nil then
        tabLangue = dataLangue[ mw.ustring.match( arg, '^(%a-)%-' ) ]
+
tabLangue = dataLangue[ mw.ustring.match( arg, '^(%a-)%-' ) ]
    end
+
end
    if tabLangue then
+
if not tabLangue then
        local nom
+
if success then
        if type( tabLangue.page ) == 'string' then
+
return string.format( langErrorMess, arg )
            nom = tabLangue.page .. '|' .. tabLangue.nom
+
else
        else
+
return '<span title="erreur dans ' .. moduleData .. '">' .. arg .. '</span>'
            nom = tabLangue.nom
+
end
        end
+
end
        return '[[' .. nom .. ']]'
+
if type( tabLangue.page ) == 'string' then
    else
+
if tabLangue.page ~= '' then
        return '<span style="color:red;">langue non reconnue : ' .. arg .. ' </span>'
+
return '[[' .. tabLangue.page .. '|' .. tabLangue.nom .. ']]'
    end
+
else
 +
return tabLangue.nom
 +
end
 +
else
 +
return '[[' .. tabLangue.nom .. ']]'
 +
end
 
end
 
end
  
-- Voir Modèle:Lang
+
 
 +
-- Voir Modèle:Langue
 
-- Paramètres :
 
-- Paramètres :
--    1 : code IETF de langue,
+
--    1 : code IETF de langue ;
--    texte ou 2 : texte dans cette langue,
+
--    texte ou 2 : texte dans cette langue ;
--    trans : translitération du texte,
+
--    trans : translittération du texte ;
 
--    dir : direction de la langue (obsolète : peut être en paramètre 1, avec code en 2 et texte en 3).
 
--    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 )
+
function Langue.langue( frame )
    local args = ( frame.getParent and frame:getParent().args ) or frame or { }         -- préparation pour appel par modèle ou direct.
+
local args = ( frame.getParent and frame:getParent().args ) or frame        -- préparation pour appel par modèle ou direct.
    local code = mw.ustring.lower( mw.text.trim( args[1] or '' ) )
+
local code = mw.ustring.lower( mw.text.trim( args[1] or '' ) )
    local texte = args.texte or ''
+
local texte = args.texte or ''
    if texte == '' then
+
if texte == '' then
        texte = args[2] or ''
+
texte = args[2] or ''
    end
+
end
    local dir = args.dir
+
local dir = args.dir
    local trans = args.trans
+
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
+
-- Décalage des paramètres si code contient la direction du texte (obsolète mais toujours possible).
        dir = code
+
if code == 'ltr' or code == 'rtl' then
        code = mw.ustring.lower( mw.text.trim( args[2] ) )
+
dir = code
        texte = args[3] or ''
+
code = mw.ustring.lower( mw.text.trim( args[2] ) or '' )
    end
+
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 codeArg = code
    local tabLangue = dataLangue[ code ]
+
    if tabLangue and tabLangue.code then
+
-- Si la langue est reconnue, la valeur de la table est prise en compte (permet de corriger les noms de langue en toutes lettres).
        code = tabLangue.code
+
local tabCode = Langue.determinationCode( code )
    else
+
local tabLangue
        -- Si elle n'est pas reconnue, on essaye uniquement le code principal.
+
if tabCode then
        local codeMain, codeSub = mw.ustring.match( code, '^(%a-)%-(.+)$' )
+
code = table.concat( tabCode, '-' )
        tabLangue = dataLangue[ codeMain ]
+
tabLangue = dataLangue[ tabCode[1] ]
        if tabLangue and tabLangue.code then
+
            -- Si le subcode est un style d'écriture (len = 4) on applique sa direction
+
local codeScript = tabCode[2]
            if string.len(codeSub) == 4 and dataLangue[ 'rtl script' ] then
+
-- Si codeScript est bien un style d'écriture (len = 4) on applique sa direction
                codeSub = string.upper( string.sub( codeSub, 1, 1 ) ) .. string.sub( codeSub, 2 )
+
if codeScript and  string.len( codeScript ) == 4 and dataLangue[ 'rtl script' ] then
                tabLangue = { code = tabLangue.code,
+
-- formatage type Latn correspondant au fromat dans dataLangue[ 'rtl script' ]
                    rtl = dataLangue[ 'rtl script' ][ codeSub ],
+
codeScript = string.upper( string.sub( codeScript, 1, 1 ) ) .. string.sub( codeScript, 2 )
                    invalide = tabLangue.invalide
+
tabLangue = { code = tabLangue.code,
                }
+
rtl = dataLangue[ 'rtl script' ][ codeScript ],
            end
+
invalide = tabLangue.invalide
            code = tabLangue.code .. '-' .. codeSub
+
}
        end
+
end
    end
+
end
 
+
    -- Prépatation du rendu de direction du texte.
+
-- Prépatation du rendu de direction du texte.
    dir = mw.ustring.lower(dir or '')
+
dir = dir and dir:lower()
    if dir == 'ltr' or dir == 'rtl' then
+
if dir ~= 'ltr' and dir ~= 'rtl' then
        dir = ' dir=' .. dir
+
dir = ( tabLangue and tabLangue.rtl and 'rtl' )
    else
+
end
        dir = (tabLangue and tabLangue.rtl and ' dir=rtl') or ''
+
    end
+
  
    -- Transliteration.
+
-- Translittération.
    if trans and trans ~= '' then
+
local htmlTrans = mw.html.create()
        trans = ' (<span class="lang-' .. code .. ' transcription" lang="' .. code .. '-Latn"'
+
if trans and trans ~= '' then
            .. ' dir="ltr">' .. trans .. '</span>)'
+
trans = trans:gsub( "^''([^'].*[^'])''$", "%1" )
    else
+
htmlTrans:wikitext( " (''" )
        trans = ''
+
:tag( 'span' )
    end
+
:addClass( 'transcription lang-' .. code )
 +
:attr( 'lang', code .. '-Latn' )
 +
:attr( 'dir', 'ltr' )
 +
:wikitext( trans )
 +
:done()
 +
:wikitext( "'')" )
 +
end
  
    -- Compilation du texte à retourner.
+
-- Compilation du texte à retourner.
    local wikiText = ''
+
local html = mw.html.create( '' )
    if code == '' then
+
if code == '' then
        wikiText = texte
+
html:wikitext( texte )
    else
+
else
        wikiText = '<span class="lang-' .. code .. '" lang="' .. code .. '"'
+
html:tag( 'span' )
            .. dir .. '>' .. texte .. '</span>' .. trans
+
:addClass( 'lang-' .. code )
    end
+
:attr{ lang = code, dir = dir }
 +
:wikitext( texte )
 +
:done()
 +
:node( htmlTrans )
 +
end
  
    -- Ajout de la catégorie Page avec code de langue invalide si le code langue non reconnu ou invalide.
+
-- 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
+
if success and ( type( tabLangue ) ~= 'table' or tabCode.invalide ) then
        local namespaceCategorisation = { [0] = true, [4] = true, [10] = true, [14] = true, [100] = true }
+
local namespaceCategorisation = { [0] = true, [4] = true, [10] = true, [12] = true, [14] = true, [100] = true }
        if namespaceCategorisation[ mw.title.getCurrentTitle().namespace ] then
+
if namespaceCategorisation[ mw.title.getCurrentTitle().namespace ] then
            wikiText = wikiText .. '[[Catégorie:Page avec code de langue invalide|' .. code .. ']]'
+
if codeArg == '' then
        end
+
codeArg = ' ' -- sinon la catégorie n'est pas wikifiée
    end
+
end
 +
html:wikitext( '[[Catégorie:Page avec code de langue invalide]] ' )
 +
:wikitext( string.format( langErrorMess, codeArg ) )
 +
end
 +
end
  
    return wikiText
+
return tostring( html )
 
end
 
end
  
-- Voir Modèle:Langue
+
-- Alias nom de fonction
-- Paramètres :
+
Langue.lang = Langue.langue
--    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
 
-- Voir Modèle:Indication de langue
 
-- Paramètres :
 
-- Paramètres :
--    1 : nom de langue,
+
--    1 : nom de langue ;
--    2 : code IETF,
+
--    2 : code IETF ;
--    texte : texte dans cette langue,
+
--    texte : texte dans cette langue ;
 
--    dir : direction de la langue.
 
--    dir : direction de la langue.
 
function Langue.indicationDeLangue( frame )
 
function Langue.indicationDeLangue( frame )
    local args = ( frame.getParent and frame:getParent().args ) or frame or { }
+
local args = ( frame.getParent and frame:getParent().args ) or frame
    local nomLangue = args[1] or ''
+
local nomLangue = args[1] or ''
    local code = args.langue or mw.text.trim( args[2] or '' )
+
local code = args.langue or mw.text.trim( args[2] or '' )
    local texte = args.texte
+
local texte = args.texte
    local dir = args.dir
+
local dir = args.dir
    local wikiText = ''
+
local wikiText = ''
    -- Cas ou le premier et/ou le deuxième paramètre est vide.
+
-- Cas le premier et/ou le deuxième paramètre est vide.
    if code .. nomLangue == '' then
+
if code .. nomLangue == '' then
        return texte
+
return texte
    elseif nomLangue == '' then
+
elseif nomLangue == '' then
        nomLangue = dataLangue[ mw.ustring.lower( code ) ]
+
nomLangue = dataLangue[ mw.ustring.lower( code ) ]
        nomLangue = (nomLangue and nomLangue.nom or '???')
+
nomLangue = (nomLangue and nomLangue.nom or '???')
    elseif code == '' then
+
elseif code == '' then
        code = dataLangue[ nomLangue ]
+
code = dataLangue[ nomLangue ]
        code = ( code and code.code or '' )
+
code = ( code and code.code or '' )
        if code == '' then
+
if code == '' then
            return texte
+
return texte
        end
+
end
    end
+
end
    -- Gestion du texte.
+
-- Gestion du texte.
    if texte and texte ~= '' then
+
if texte and texte ~= '' then
        texte = '&nbsp;' .. Langue.lang{ code, dir = dir, texte = texte }
+
texte = '&nbsp;' .. Langue.lang{ code, dir = dir, texte = texte }
    else
+
else
        texte = ''
+
texte = ''
    end
+
end
    -- Compilation de l'indicateur de langue et du texte.
+
-- Compilation de l'indicateur de langue et du texte.
    wikiText = '<span class="indicateur-langue">(<abbr class="abbr" title="Langue : '
+
local html = mw.html.create()
    .. nomLangue .. '">'
+
html:tag( 'span' )
    .. code .. '</abbr>)</span>'
+
:addClass( 'indicateur-langue' )
    .. texte
+
:wikitext( '(' )
    return wikiText
+
:tag( 'abbr' )
 +
:addClass( 'abbr' )
 +
:attr( 'title', 'Langue : ' .. nomLangue )
 +
:wikitext( code )
 +
:done()
 +
:wikitext( ')' )
 +
:done()
 +
:wikitext( texte )
 +
 +
return tostring( html )
 
end
 
end
  
-- Voir Modèle:Multiling
+
-- Voir Modèle:Mul
-- Paramètres : codes IETF ou noms de langue, en nombre indéfini. (string ou nil uniquement)
+
-- Paramètres : codes IETF ou noms de langue, en nombre indéfini (string ou nil uniquement).
 
function Langue.indicationMultilingue( frame )
 
function Langue.indicationMultilingue( frame )
    local args = (frame.getParent and frame:getParent().args) or frame
+
local args = (frame.getParent and frame:getParent().args) or frame
    local listeNom = { }
+
local listeNom = { }
    local listeCode = { }
+
local listeCode = { }
    local tabLangue
+
local tabLangue
    -- Valeur par défaut du premier paramètre = 'mul'.
+
-- Valeur par défaut du premier paramètre = 'mul'.
    code = mw.ustring.lower( mw.text.trim( args[1] or '' ) )
+
local code = mw.text.trim( args[1] or '' )
    if code == '' then
+
if code == '' then
        code = 'mul'
+
code = 'mul'
    end
+
end
    -- Ajout des noms et codes de langue de chaque paramètre dans listeNom et ListeCode.
+
    local i = 1
+
if not args[2] and not dataLangue[ mw.ustring.lower( code ) ] then
    repeat  
+
local split = mw.text.split( code, '[+,;:/ .]+' )
        tabLangue = dataLangue[ code ]
+
if #split > 1 then
        if type( tabLangue ) == 'table' then
+
return Langue.indicationMultilingue( split )
            table.insert( listeNom, tabLangue.nom )
+
end
            table.insert( listeCode, tabLangue.code )
+
end
        else
+
-- Ajout des noms et codes de langue de chaque paramètre dans listeNom et ListeCode.
            table.insert( listeNom, '???' )
+
local i = 1
            local erreur = ' <span style="color:red; font-size:120%;">langue non reconnue : '  
+
repeat
                .. code .. ' </span>'
+
code = mw.ustring.lower( code )
            table.insert( listeCode, erreur )
+
local tabLangue = dataLangue[ code ]
        end
+
if not tabLangue then
        i = i+1
+
code = mw.text.split( code, '-' )[1]
        code = mw.ustring.lower( mw.text.trim( args[i] or '' ) )
+
tabLangue = dataLangue[ code ]
    until code == ''  
+
end
    -- Préparation et renvoie du texte.
+
if type( tabLangue ) == 'table' then
    local n = #listeCode
+
table.insert( listeNom, tabLangue.nom )
    local pluriel = ''
+
table.insert( listeCode, tabLangue.code )
    if n == 0 then
+
elseif success then
        return ''
+
table.insert( listeNom, '???' )
    elseif n > 1 then
+
local erreur = ' ' .. string.format( langErrorMess, code )
        pluriel = 's'
+
table.insert( listeCode, erreur )
    end
+
else
    local wikiText = '<span class="indicateur-langue">(<abbr class="abbr" title="Langue' .. pluriel .. ' : '
+
table.insert( listeNom, '??? (erreur dans ' .. moduleData .. ')' )
        .. mw.text.listToText( listeNom ) .. '">'
+
table.insert( listeCode, code )
        .. table.concat( listeCode, '+' ) .. '</abbr>)</span>'  
+
end
    return wikiText
+
i = i + 1
 +
code = mw.text.trim( args[i] or '' )
 +
until code == ''
 +
 +
-- Préparation et renvoi du texte.
 +
local n = #listeCode
 +
local pluriel = ''
 +
if #listeCode == 0 then
 +
return ''
 +
elseif n > 1 then
 +
pluriel = 's'
 +
end
 +
 +
local html = mw.html.create( 'span' )
 +
html:addClass( 'indicateur-langue' )
 +
:wikitext( '(' )
 +
:tag( 'abbr' )
 +
:addClass( 'abbr' )
 +
:attr( 'title', 'Langue' .. pluriel .. ' : ' .. mw.text.listToText( listeNom ) )
 +
:wikitext( table.concat( listeCode, '+' ) )
 +
:done()
 +
:wikitext( ')' )
 +
:done()
 +
 +
return tostring( html )
 
end
 
end
 +
  
 
-- Voir Modèle:Langue avec nom
 
-- Voir Modèle:Langue avec nom
 
-- Paramètres :
 
-- Paramètres :
--    1 : code IETF de langue,
+
--    1 : code IETF de langue ;
--    texte ou 2 : texte dans cette langue,
+
--    texte ou 2 : texte dans cette langue ;
--    trans : translitération du texte,
+
--    trans : translittération du texte ;
 
--    dir : direction de la langue.
 
--    dir : direction de la langue.
 
function Langue.langueAvecNom( frame )
 
function Langue.langueAvecNom( frame )
    local args = ( frame.getParent and frame:getParent().args ) or frame or { }
+
local args = ( frame.getParent and frame:getParent().args ) or frame
    local code = mw.ustring.lower( mw.text.trim( args [1] or '') )
+
local code = mw.ustring.lower( mw.text.trim( args [1] or '') )
    local texte = args.texte or args[2] or ''
+
local texte = args.texte or args[2] or ''
    local trans = args.trans
+
local trans = args.trans
    local dir = args.dir
+
local dir = args.dir
    local wikiText = ''
+
local wikiText = ''
  
    -- Détection de la direction du texte.
+
-- Détection de la direction du texte.
    if code == 'ltr' or code == 'rtl' then
+
if code == 'ltr' or code == 'rtl' then
        dir = code
+
dir = code
        code = mw.ustring.lower( mw.text.trim( args[2] ) )
+
code = mw.ustring.lower( mw.text.trim( args[2] ) )
        texte = args[3] or ''
+
texte = args[3] or ''
    end
+
end
  
    -- Définition du nom de la langue en français.
+
-- Définition du nom de la langue en français.
    local nom = Langue.nomLangue{ code }
+
local nom = Langue.nomLangue{ code }
  
    if texte ~= '' then
+
if texte ~= '' then
        texte = '&nbsp;' .. Langue.lang{ code, dir = dir, texte = texte, trans = trans }
+
texte = '&nbsp;' .. Langue.lang{ code, dir = dir, texte = texte, trans = trans }
    end
+
end
  
    wikiText = nom .. ' :' .. texte
+
wikiText = nom .. ' :' .. texte
  
    return wikiText
+
return wikiText
 
end
 
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.
+
-- latinOnly détermine si la chaine fournie contien uniquement des caractère latin (étendu, unicode < 880)
 +
function Langue.nonLatin( frame )
 +
local texte = premierParametre( frame )
 +
for codepoint in mw.ustring.gcodepoint( texte ) do
 +
if codepoint > 879 and not (                  --  > 036F
 +
codepoint > 7423 and codepoint < 7936 or  -- suppléments phonétique, diacritiques et latin  (1D00 à 1EFF)
 +
codepoint > 8191 and codepoint < 11392 or -- espace, indices, monaies et symboles divers (2000 à 2C7F)
 +
codepoint > 42783 and codepoint < 43008  -- latin étendu D  (A720 à A7FF)
 +
) then
 +
return true
 +
end
 +
end
 +
return false
 +
end
 +
 
 +
-- erreurModuleData affiche 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ées et ceux qui veulent surveiller cette page.
 
function Langue.erreurModuleData()
 
function Langue.erreurModuleData()
    if success == false then  
+
if success == false then
        local message = [[<strong class="error">Le chargement du module Langue/Data génère une erreur : </strong><br />%s<br />
+
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>
+
<span class="error">Cette erreur doit être corrigée au plus vite car des milliers de pages ne s'affichent pas correctement.</span>
 
]]
 
]]
        return string.format( message, resultat )
+
return string.format( message, resultat )
    end
+
end
 
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.
 
+
--tableauLangues génère un tableau triable de la liste des langues disponible dans Module:langue/Data.
+
 
function Langue.tableauLangues()
 
function Langue.tableauLangues()
    if type( dataLangue ) ~= 'table' then
+
if type( dataLangue ) ~= 'table' then
        return
+
return
    end
+
end
  
    local tableau = { }  
+
local tableau = { }
    local entete = [[{| class="wikitable alternance sortable"
+
local entete = [[{| class="wikitable alternance sortable"
 
|-
 
|-
 
!scope=col|Alias
 
!scope=col|Alias
!scope=col|code IETF
+
!scope=col|Code IETF
 
!scope=col|Nom principal
 
!scope=col|Nom principal
!scope=col|Page
+
!scope=col|Page (si différente du nom)
 
!scope=col|RTL
 
!scope=col|RTL
!scope=col|invalide]]
+
!scope=col|Invalide]]
  
    local lignetab, lignesrt
+
local ligneTab, ligneSrt
    for i, v in pairs( dataLangue ) do
+
for i, v in pairs( dataLangue ) do
        if v.code then
+
if v.code then
            lignetab = {
+
ligneTab = {
                i,
+
i,
                v.code,
+
v.code,
                v.nom,
+
v.nom,
                v.page or '',
+
v.page or '',
                v.rtl and '[[Image:Yes check.svg|15px|oui|lien=]]' or '',
+
v.rtl and '[[Image:Yes check.svg|15px|oui|lien=]]' or '',
                v.invalide 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|' )
+
ligneSrt = table.concat( ligneTab, '\n|' )
            table.insert( tableau, lignesrt )
+
table.insert( tableau, ligneSrt )
        end
+
end
    end  
+
end
    table.sort( tableau )
+
table.sort( tableau )
    table.insert( tableau, 1, entete )
+
table.insert( tableau, 1, entete )
    table.insert( tableau, '}' )
+
table.insert( tableau, '}' )
   
+
    return table.concat( tableau, '\n|-\n|' )
+
return table.concat( tableau, '\n|-\n|' )
 
end
 
end
  
-- listeCodeAlias génére une liste les langues sont la forme : * code : alias1, alias2
+
-- listeCodeAlias génère une liste ; les langues sont la forme : * code : alias1, alias2
 
function Langue.listeCodeAlias ()
 
function Langue.listeCodeAlias ()
    if type( dataLangue ) ~= 'table' then
+
if type( dataLangue ) ~= 'table' then
        return
+
return
    end
+
end
    local languesTab, listeCodesAlias = { }, { }
+
local languesTab, listeCodesAlias = { }, { }
    local code, alias, codeAlias
+
local code, alias, codeAlias
    for i, v in pairs( dataLangue ) do
+
for i, v in pairs( dataLangue ) do
        -- on construit un table avec pour indice les code de langue, et pour valeur une table avec la liste des alias
+
-- on construit un table avec pour indices les codes de langue, et pour valeurs une table avec la liste des alias
        code = v.code
+
code = v.code
        if code then
+
if code and not v.invalide then
            languesTab[code] = languesTab[code] or { }
+
languesTab[code] = languesTab[code] or { }
            if i ~= mw.ustring.lower( code ) then
+
if i ~= mw.ustring.lower( code ) then
                table.insert( languesTab[code], i )
+
table.insert( languesTab[code], i )
            end
+
end
        end
+
end
    end
+
end
    for i, v in pairs( languesTab ) do
+
for i, v in pairs( languesTab ) do
        -- transformation en un table séquence, avec pour valeur une chaine correspondant à une ligne de la liste
+
-- transformation en un table séquence, avec pour valeur une chaine correspondant à une ligne de la liste
        alias = table.concat( v, ', ' )
+
alias = table.concat( v, ', ' )
        if alias == '' then
+
if alias == '' then
            codeAlias = '\n* <code>' .. i .. '</code>'
+
codeAlias = '\n* <code>' .. i .. '</code>'
        else
+
else
            codeAlias = '\n* <code>' .. i .. '</code> : ' .. alias
+
codeAlias = '\n* <code>' .. i .. '</code> : ' .. alias
        end
+
end
        table.insert( listeCodesAlias, codeAlias )
+
table.insert( listeCodesAlias, codeAlias )
    end
+
end
    table.sort( listeCodesAlias )
+
table.sort( listeCodesAlias )
 
+
    return table.concat( listeCodesAlias )
+
return table.concat( listeCodesAlias )
 +
end
 +
 
 +
-- listeCodeAlias génère une liste ; les langues sont la forme :  * code : alias1, alias2
 +
function Langue.listeAliasCode ()
 +
if type( dataLangue ) ~= 'table' then
 +
return
 +
end
 +
local languesTab = { '' }
 +
local code
 +
for i, v in pairs( dataLangue ) do
 +
-- on construit un table avec pour indices les codes de langue, et pour valeurs une table avec la liste des alias
 +
code = v.code
 +
if code and i ~= code and not v.invalide then
 +
table.insert( languesTab, i .. ' = ' .. code )
 +
end
 +
end
 +
table.sort( languesTab )
 +
 +
return table.concat( languesTab, '\n*' )
 
end
 
end
  
 
return Langue
 
return Langue

Version actuelle en date du 7 février 2017 à 21:43

La documentation pour ce module peut être créée à Module:Langue/doc

local Langue = { }

-- Chargement de la base de données des langues avec gestion d'erreur.
local dataLangue
local moduleData = 'Module:Langue/Data'
local langErrorMess = '<span class=error>langue non reconnue : %s</span>'
local success, resultat = pcall (mw.loadData, moduleData )
success = success and type( resultat.en ) == 'table'
if success then
	dataLangue = resultat
else
	-- Base de données a minima en cas de bug sur le Module:Langue/Data
	dataLangue = { en = { code = 'en', nom = anglais },
		fr = { code = 'fr', nom = 'français' },
		de = { code = 'de', nom = 'allemand' },
		es = { code = 'es', nom = 'espagnol' },
		it = { code = 'it', nom = 'italien'  },
		la = { code = 'la', nom = 'latin'    },
		['rtl script'] = { Arab = true }
	}
	dataLangue.anglais = dataLangue.en
	dataLangue['français'] = dataLangue.fr
	dataLangue.allemand = dataLangue.de
	dataLangue.espagnol = dataLangue.es
	dataLangue.italien = dataLangue.it
end

-- premierParametre renvoie le premier paramètre de Frame, que celui-ci ait été passé 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 arguments 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 minuscules.
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

-- determinationCode retourne une table contenant le code de langue principal et la liste des subcode
-- si le code de langue principal n'est pas reconnu, retourne nil.
function Langue.determinationCode( langue )
	if type( langue ) == 'string' and langue ~= '' then
		local tabCode = mw.text.split( langue, '-' )
		local tabLangue = dataLangue[ mw.ustring.lower( tabCode[1] ) ]
		if tabLangue and tabLangue.code then
			tabCode[1] = tabLangue.code
			if tabLangue.invalide then
				tabCode.invalide=true
			end
			return tabCode
		end
	end
end

-- Voir Modèle:Code langue
-- Paramètre :
--     1  : nom de langue.
function Langue.codeLangue( frame )
	local arg = premierParametre( frame, true )
	local tabCode = Langue.determinationCode( arg )
	return ( tabCode and table.concat( tabCode, '-' ) ) 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 tabCode = Langue.determinationCode( arg )
	return ( tabCode and table.concat( tabCode, '-' ) ) or ''
end


-- Voir Modèle:Direction langue
-- Paramètre :
--     1  : nom de langue ou code IETF.
function Langue.directionLangue( frame )
	local arg = premierParametre( frame, true )
	if type( arg ) ~= 'string' or arg == '' then
		return 'ltr'
	end
	-- séparation du code de langue en code principal et les différents subcode.
	local tabCode = Langue.determinationCode( arg )
	if tabCode then
		-- on essaye de savoir si la direction est de droite à gauche
		local codeScript = tabCode[2]
		if codeScript and string.len( codeScript ) == 4 and dataLangue[ 'rtl script' ] then
			-- il y a un subcode d'écritrure, c'est lui qui est pris en compte
			codeScript = string.upper( string.sub( codeScript, 1, 1 ) ) .. string.sub( codeScript, 2 )
			if dataLangue[ 'rtl script' ][ codeScript ] then
				return 'rtl'
			end
		else
			-- il n'y a pas de sub-code d'écriture, on prend en compte le code de langue principal.
			local tabLangue = dataLangue[ tabCode[1] ]
			if tabLangue and tabLangue.rtl then
				return 'rtl'
			end
		end
	end
	
	-- la langue n'est pas écrite de droite à gauche, donc ltr.
	return 'ltr'
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 class=error>langue non précisée</span>'
	end
	local tabLangue = dataLangue[ arg ]
	if tabLangue == nil then
		tabLangue = dataLangue[ mw.ustring.match( arg, '^(%a-)%-' ) ]
	end
	if not tabLangue then
		if success then
			return string.format( langErrorMess, arg )
		else
			return '<span title="erreur dans ' .. moduleData .. '">' .. arg .. '</span>'
		end
	end
	if type( tabLangue.page ) == 'string' then
		if tabLangue.page ~= '' then
			return '[[' .. tabLangue.page .. '|' .. tabLangue.nom .. ']]'
		else
			return tabLangue.nom
		end
	else
		return '[[' .. tabLangue.nom .. ']]'
	end
end


-- Voir Modèle:Langue
-- Paramètres :
--    1 : code IETF de langue ;
--    texte ou 2 : texte dans cette langue ;
--    trans : translitté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.langue( frame )
	local args = ( frame.getParent and frame:getParent().args ) or frame         -- 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 (obsolète mais toujours possible).
	if code == 'ltr' or code == 'rtl' then
		dir = code
		code = mw.ustring.lower( mw.text.trim( args[2] ) or '' )
		texte = args[3] or ''
	end
	local codeArg = code
	
	-- Si la langue est reconnue, la valeur de la table est prise en compte (permet de corriger les noms de langue en toutes lettres).
	local tabCode = Langue.determinationCode( code )
	local tabLangue
	if tabCode then
		code = table.concat( tabCode, '-' )
		tabLangue = dataLangue[ tabCode[1] ]
		
		local codeScript = tabCode[2]
		-- Si codeScript est bien un style d'écriture (len = 4) on applique sa direction
		if codeScript and  string.len( codeScript ) == 4 and dataLangue[ 'rtl script' ] then
			-- formatage type Latn correspondant au fromat dans dataLangue[ 'rtl script' ]
			codeScript = string.upper( string.sub(  codeScript, 1, 1 ) ) .. string.sub(  codeScript, 2 )
			tabLangue = { code = tabLangue.code,
				rtl = dataLangue[ 'rtl script' ][ codeScript ],
				invalide = tabLangue.invalide
			}
		end
	end
		
	-- Prépatation du rendu de direction du texte.
	dir = dir and dir:lower()
	if dir ~= 'ltr' and dir ~= 'rtl' then
		dir = ( tabLangue and tabLangue.rtl and 'rtl' )
	end

	-- Translittération.
	local htmlTrans = mw.html.create()
	if trans and trans ~= '' then
		trans = trans:gsub( "^''([^'].*[^'])''$", "%1" )
		htmlTrans:wikitext( " (''" )
				:tag( 'span' )
					:addClass( 'transcription lang-' .. code )
					:attr( 'lang', code .. '-Latn' )
					:attr( 'dir', 'ltr' )
					:wikitext( trans )
					:done()
				:wikitext( "'')" )
	end

	-- Compilation du texte à retourner.
	local html = mw.html.create( '' )
	if code == '' then
		html:wikitext( texte )
	else
		html:tag( 'span' )
				:addClass( 'lang-' .. code )
				:attr{ lang = code, dir = dir }
				:wikitext( texte )
				:done()
			:node( htmlTrans )
	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 tabCode.invalide ) then
		local namespaceCategorisation = { [0] = true, [4] = true, [10] = true, [12] = true, [14] = true, [100] = true }
		if namespaceCategorisation[ mw.title.getCurrentTitle().namespace ] then
			if codeArg == '' then
				codeArg = ' ' 	-- sinon la catégorie n'est pas wikifiée
			end
			html:wikitext( '[[Catégorie:Page avec code de langue invalide]] ' )
				:wikitext( string.format( langErrorMess, codeArg ) )
		end
	end

	return tostring( html )
end

-- Alias nom de fonction
Langue.lang = Langue.langue


-- 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
	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 où 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 = '&nbsp;' .. Langue.lang{ code, dir = dir, texte = texte }
	else
		texte = ''
	end
	-- Compilation de l'indicateur de langue et du texte.
	local html = mw.html.create()
	html:tag( 'span' )
			:addClass( 'indicateur-langue' )
			:wikitext( '(' )
			:tag( 'abbr' )
				:addClass( 'abbr' )
				:attr( 'title', 'Langue : ' .. nomLangue )
				:wikitext( code )
				:done()
			:wikitext( ')' )
			:done()
		:wikitext( texte )
	
	return tostring( html )
end

-- Voir Modèle:Mul
-- 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'.
	local code = mw.text.trim( args[1] or '' )
	if code == '' then
		code = 'mul'
	end
	
	if not args[2] and not dataLangue[ mw.ustring.lower( code ) ] then
		local split = mw.text.split( code, '[+,;:/ .]+' )
		if #split > 1 then 
			return Langue.indicationMultilingue( split )
		end
	end
	-- Ajout des noms et codes de langue de chaque paramètre dans listeNom et ListeCode.
	local i = 1
	repeat
		code = mw.ustring.lower( code )
		local tabLangue = dataLangue[ code ]
		if not tabLangue then
			code = mw.text.split( code, '-' )[1]
			tabLangue = dataLangue[ code ]
		end
		if type( tabLangue ) == 'table' then
			table.insert( listeNom, tabLangue.nom )
			table.insert( listeCode, tabLangue.code )
		elseif success then
			table.insert( listeNom, '???' )
			local erreur = ' ' .. string.format( langErrorMess, code )
			table.insert( listeCode, erreur )
		else
			table.insert( listeNom, '??? (erreur dans ' .. moduleData .. ')' )
			table.insert( listeCode, code )
		end
		i = i + 1
		code = mw.text.trim( args[i] or '' )
	until code == ''
	
	-- Préparation et renvoi du texte.
	local n = #listeCode
	local pluriel = ''
	if #listeCode == 0 then
		return ''
	elseif n > 1 then
		pluriel = 's'
	end
	
	local html = mw.html.create( 'span' )
	html:addClass( 'indicateur-langue' )
		:wikitext( '(' )
		:tag( 'abbr' )
			:addClass( 'abbr' )
			:attr( 'title', 'Langue' .. pluriel .. ' : ' .. mw.text.listToText( listeNom ) )
			:wikitext( table.concat( listeCode, '+' ) )
			:done()
		:wikitext( ')' )
		:done()
		
	return tostring( html )
end


-- Voir Modèle:Langue avec nom
-- Paramètres :
--    1 : code IETF de langue ;
--    texte ou 2 : texte dans cette langue ;
--    trans : translittération du texte ;
--    dir : direction de la langue.
function Langue.langueAvecNom( frame )
	local args = ( frame.getParent and frame:getParent().args ) or frame
	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 = '&nbsp;' .. Langue.lang{ code, dir = dir, texte = texte, trans = trans }
	end

	wikiText = nom .. ' :' .. texte

	return wikiText
end

---
-- latinOnly détermine si la chaine fournie contien uniquement des caractère latin (étendu, unicode < 880)
function Langue.nonLatin( frame )
	local texte = premierParametre( frame )
	for codepoint in mw.ustring.gcodepoint( texte ) do
		if codepoint > 879 and not (                  --  > 036F
			codepoint > 7423 and codepoint < 7936 or  -- suppléments phonétique, diacritiques et latin  (1D00 à 1EFF)
			codepoint > 8191 and codepoint < 11392 or -- espace, indices, monaies et symboles divers (2000 à 2C7F)
			codepoint > 42783 and codepoint < 43008   -- latin étendu D  (A720 à A7FF)
		) then
			return true
		end
	end
	return false
end

-- erreurModuleData affiche 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ées 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 pages ne s'affichent pas correctement.</span>
]]
		return string.format( message, resultat )
	end
end

-- 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 (si différente du nom)
!scope=col|RTL
!scope=col|Invalide]]

	local ligneTab, ligneSrt
	for i, v in pairs( dataLangue ) do
		if v.code then
			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
	end
	table.sort( tableau )
	table.insert( tableau, 1, entete )
	table.insert( tableau, '}' )
	
	return table.concat( tableau, '\n|-\n|' )
end

-- listeCodeAlias génère une liste ; les langues sont la forme : * code : alias1, alias2
function Langue.listeCodeAlias ()
	if type( dataLangue ) ~= 'table' then
		return
	end
	local languesTab, listeCodesAlias = { }, { }
	local code, alias, codeAlias
	for i, v in pairs( dataLangue ) do
		-- on construit un table avec pour indices les codes de langue, et pour valeurs une table avec la liste des alias
		code = v.code
		if code and not v.invalide then
			languesTab[code] = languesTab[code] or { }
			if i ~= mw.ustring.lower( code ) then
				table.insert( languesTab[code], i )
			end
		end
	end
	for i, v in pairs( languesTab ) do
		-- transformation en un table séquence, avec pour valeur une chaine correspondant à une ligne de la liste
		alias = table.concat( v, ', ' )
		if alias == '' then
			codeAlias = '\n* <code>' .. i .. '</code>'
		else
			codeAlias = '\n* <code>' .. i .. '</code> : ' .. alias
		end
		table.insert( listeCodesAlias, codeAlias )
	end
	table.sort( listeCodesAlias )
	
	return table.concat( listeCodesAlias )
end

-- listeCodeAlias génère une liste ; les langues sont la forme :  * code : alias1, alias2
function Langue.listeAliasCode ()
	if type( dataLangue ) ~= 'table' then
		return
	end
	local languesTab = { '' }
	local code
	for i, v in pairs( dataLangue ) do
		-- on construit un table avec pour indices les codes de langue, et pour valeurs une table avec la liste des alias
		code = v.code
		if code and i ~= code and not v.invalide then
			table.insert( languesTab, i .. ' = ' .. code )
		end
	end
	table.sort( languesTab )
	
	return table.concat( languesTab, '\n*' )
end

return Langue