Module:Drapeau/Brouillon
Apparence
[voir] [modifier] [historique] [purger]
Exemples[modifier le code]
Pour des exemples, voir la page de test permettant de tester diverses modifications apportées.
code | rendu | modèle |
---|---|---|
{{#Invoke:Drapeau/Brouillon | pays }} | ????? | |
{{#Invoke:Drapeau/Brouillon | pays | France }} | France | France |
{{#Invoke:Drapeau/Brouillon | pays | Égypte}} | Égypte | Égypte |
{{#Invoke:Drapeau/Brouillon | pays | Belgique}} | Belgique | Belgique |
{{#Invoke:Drapeau/Brouillon | pays | Népal}} | Népal | Népal |
{{#Invoke:Drapeau/Brouillon | pays | Équateur}} | Équateur | Équateur |
{{#Invoke:Drapeau/Brouillon | pays | États-Unis}} | États-Unis | États-Unis |
{{#Invoke:Drapeau/Brouillon | pays | Bordurie}} | Bordurie | ????? |
{{#Invoke:Drapeau/Brouillon | pays | FRA}} {{#Invoke:Drapeau/Brouillon | pays | CIO=FRA}} |
France | France |
{{#Invoke:Drapeau/Brouillon | pays | France |align=right}} | France | France |
{{#Invoke:Drapeau/Brouillon | pays | France |lien=non}} | France | |
{{#Invoke:Drapeau/Brouillon | pays | France |domaine=football}} | France | France |
{{#Invoke:Drapeau/Brouillon | pays | France |domaine=Marine de guerre}} | France | France |
{{#Invoke:Drapeau/Brouillon | pays | Égypte |domaine=Marine de guerre}} | Égypte | Égypte |
{{#Invoke:Drapeau/Brouillon | pays | Royaume-Uni |domaine=Marine de guerre}} | Royaume-Uni | Royaume-Uni |
{{#Invoke:Drapeau/Brouillon | pays | France |domaine=JO}} | France | France |
{{#Invoke:Drapeau/Brouillon | pays | France |domaine=JO CIO}} | France | FRA |
{{#Invoke:Drapeau/Brouillon | pays|France|domaine=Sport CIO}} | France | Laurent Jalabert (France) |
{{#Invoke:Drapeau/Brouillon | pays|France|2000|domaine=JO CIO|cible=[[Tony Estanguet]]}} | France | Tony Estanguet (FRA) |
{{#Invoke:Drapeau/Brouillon | pays | France | année=1820}} | France | France |
{{#Invoke:Drapeau/Brouillon | pays | France |domaine=football|compétition=en|édition=2000}} | France | France |
{{#Invoke:Drapeau/Brouillon | pays | France |domaine=compétition|compétition=jo|édition=2000}} | France | France |
{{#Invoke:Drapeau/Brouillon | pays | France |domaine=compétition|compétition=jo|édition=1992}} | France | France |
{{#Invoke:Drapeau/Brouillon | pays | France |domaine=compétition|compétition=jo|édition=ete1992}} | France | France |
{{#Invoke:Drapeau/Brouillon | pays | France |domaine=handball|compétition=jo|édition=2012}} | France | France |
{{#Invoke:Drapeau/Brouillon | pays | France |domaine=pelote basque}} | France | France |
Syntaxe | Aperçu | Aperçu |
---|---|---|
{{drapeau2|Belgique|t=1}}
|
Belgique | Belgique |
{{drapeau2|Égypte|t=1}}
|
Égypte | Égypte |
{{drapeau2|France|t=1}}
|
France | France |
{{drapeau2|CIO=ISV|t=1}}
|
||
{{drapeau2|Népal|t=1}}
|
Népal | Népal |
Domaines paramétrés[modifier le code]
{{#Invoke:Drapeau/Brouillon|list|libelle|142|31|30}}
(la fonction n'existe pas encore)
Pays paramétrés[modifier le code]
{{#Invoke:Drapeau/Brouillon|list|pays}}
(la fonction n'existe pas encore)
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.
--[[
This module is intended to replace the functionality of {{drapeau2}} and related
templates. It provides several methods, including
]]
drapeau = {};
-- Chargement de la banque de données des langues avec gestion d'erreur.
local gdata
local linguistic = require "Module:Linguistique"
local success, resultat = pcall (mw.loadData, "Module:Country data/liste" )
-- chargement des données
if success then
gdata = resultat
else
-- Banque de données à minima en cas de bogue dans le Module:Langue/Data
gdata={
['france']={item="Q142", flag= "Flag_of_France.svg", name ="France"}
}
end
local gdomaine
local success, resultat = pcall (mw.loadData, "Module:Drapeau/Domaine/Brouillon" )
if success then
gdomaine = resultat
end
local function _getCompetition(c,aaaa)
local rep="";
if(c=="CM" or c=="coupedumonde") then
rep="à la Coupe du monde"
elseif(c=="CE" or c=="euro") then
rep="au championnat d'Europe"
elseif(c=="ChM") then
rep="au championnat du monde"
elseif(c=="CAN" or c=="coupedesconfederations") then
rep="à la Coupe des Confédérations"
elseif(c=="en" ) then
rep="en"
elseif(c=="jo" ) then
rep="aux Jeux olympiques"
elseif(c=="jp" ) then
rep="aux Jeux paralympiques"
end
--edition
if(aaaa ~= nil and aaaa ~= "") then
if(c=="jo" or c=="jp" ) then
local o=gdomaine.jo["_"..aaaa];
if(o ~= nil) then
rep=rep.." "..o
end
else
rep=rep.." "..aaaa
end
end
return rep
end
--[[
pays
Affiche le pays accompagné de son drapeau {{drapeau2}}
Usage:
{{ Invoke:Drapeau | pays | France }}
]]
local function printIcon(filescr, alt, size, border)
if (border ~= "no") or (border == false) then
border='border|'
end
if not alt then
alt = ''
end
return '<span class="flagicon">' ..
'[[Fichier:' .. filescr .. '|' .. size ..'px|' .. border .. alt ..']]' ..
'</span>';
end
local function getData(datatable, typedata, topic, year)
-- récupères les données stockées sur datatable
-- typedata = flag ou nom
-- datedata = year
-- domaine = arméée etc.)
local val, alt
if not datatable[typedata] then
return error('demande invalide')
end
if type(datatable[typedata]) == 'string' then
val = datatable[typedata]
return val
end
alt = datatable[typedata].alt
local numericdate
if year then
numericdate = tonumber(year)
end
if numericdate then
local bestdate = -10000
for i, j in pairs (datatable[typedata]) do
local k = tonumber(i)
if k and (k < numericdate) and (k > bestdate) then
val = j
bestdate = k
end
end
end
if not val then
val = datatable[typedata][topic] or datatable[typedata]['default']
end
return val, alt
end
local function printLabel(data, topic)
local label
if not name then
return getData(data, 'name')
end
end
local function printLink(areadata, topic)
if areadata.link then
return areadata.link[topic] or areadata.link['default']
end
return mw.wikibase.sitelink(data.item)
end
local function applyregex(str, areadata)
local cio = 'code CIO (en attente)' --require('Module:Wikidata')._formatStatements({entity= areadata.item, property= 'P984'}) or '??'
local label = getData(areadata, 'name')
local of = linguistic.of(label, areadata.genre)
str = mw.ustring.gsub(str, '$de$label', of)
str = mw.ustring.gsub(str, '$label', label)
str = mw.ustring.gsub(str, '$cio', 'cio')
if string.find(str, '$gentile') then
local function get(genre) return getData(areadata, 'adjective', genre) end
local gentileMS, gentileFS, gentileMP, gentileFP = get('ms'), get('fs'), get('mp'), get('fp')
str = mw.ustring.gsub(str, '$gentileMS', gentileMS)
str = mw.ustring.gsub(str, '$gentileFS', gentileFS)
str = mw.ustring.gsub(str, '$gentileMP', gentileMP)
str = mw.ustring.gsub(str, '$gentileFP', gentileFP)
end
return str
end
local function standardText(areadata, topicdata)
-- format standards stockées dans Module:Drapeau/Domaine
local link = topicdata.link
local label = topicdata.label
return link, label
end
local function getDatatable(zone)
zone = mw.ustring.lower(zone)
if gdata[zone] then
return require('Module:Country data/' .. gdata[zone])
else -- si le module existe mais n'est pas dans la liste
return require('Module:Country data/' .. zone)
end
end
function drapeau.List(frame)
return drapeau.list(frame)
end
function drapeau._drapeau(args)
-- nettoyage des paramètres
for i, j in pairs(args) do
args[i] = mw.text.trim(j) -- remove whitespaces
if args[i] == '' then args[i] = nil end
end
-- ajout des valeurs par défaut
local zone = args[1]
local taille = args["taille"] or '20x15'
local domaine = args["domaine"]
local typedrapeau = args["type"]
if domaine and not gdomaine.domainelist["domaine"] then
domaine = mw.ustring.lower(string.gsub(domaine, " ", ""))
domaine = linguistic.toascii(domaine)
end
domaine = gdomaine.domainelist[domaine]
if args["domaine"] and not domaine then
return error("domaine non reconnu:" .. args["domaine"])
end
local align = args["align"] or 'left'
local lien = args["lien"]
local label = args["label"]
local annee = args[2] or args["année"] or ''
local align = args["align"] or "left"
local cible = args["cible"]
local competition = args["compétition"]
local extra = ''
-- chargement des données
if not zone then
return error('paramètre 1 (pays) manquant')
end
local success, data = pcall(getDatatable, zone)
if not success then
return error('pays invalide')
end
-- image
local fichierdrapeau, alt = getData(data, 'flag', domaine, annee)
local icon -- le fichier mis en forme
if fichierdrapeau then
icon = printIcon(fichierdrapeau, alt, taille, border)
end
if (label == 'non') or (label == '-') then
return icon
end
if (lien == 'non') or (lien == '-') then -- ne devrait pas plutôt retourner un texte sans lien ?
return icon
end
if domaine then
lien, label = standardText(data, domaine)
end
if (not lien) then
lien = printLink(data, typedrapeau)
end
if (not label) then
label = printLabel(data, typedrapeau)
end
if competition then
competition = _getCompetition(linguistic.toascii(args["compétition"]),args["édition"])
end
if lien and competition then
lien = lien .. ' ' .. competition
end
if lien then
text = '[[' .. lien .. '|' .. label .. ']]'
end
if cible then
text = cible .. ' (' .. text .. ')'
end
if string.find(text, '$') then -- si les données sont extraites d'un formulaire standard comme module:Drapeau/Domaine
text = applyregex(text, data)
end
if align == 'right' then
return text .. ' ' ..icon
else
return icon .. ' ' .. text
end
end
function drapeau.pays(frame)
local success, val = pcall(drapeau._drapeau, frame.args)
if success then
return val
end
-- return drapeau._drapeau(frame.args)
return frame.args[1]
end
return drapeau