Aller au contenu

Module:Utilisateur:SyntaxTerror/2

Une page de Wikipédia, l'encyclopédie libre.
Ceci est une version archivée de cette page, en date du 17 août 2013 à 05:42 et modifiée en dernier par SyntaxTerror (discuter | contributions) (version "ça marche, mais pas top pour un seul article" (pas d'erreur 4)). Elle peut contenir des erreurs, des inexactitudes ou des contenus vandalisés non présents dans la version actuelle.

 Documentation[voir] [modifier] [historique] [purger]
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

-- 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://'
    .. lang1 .. '.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://'
    .. lang2 .. '.wikipedia.org/wiki/'
    .. mw.uri.encode( art2 , "WIKI" ) .. '?action=history liste des auteurs]</span>)'

    
--[=[
    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>.'
]=]


    return wikitext
end
    
return Langue
--[=[

Utilisateur:SyntaxTerror/Brouillon/Module2

]=]