Module:glossaire

Définition, traduction, prononciation, anagramme et synonyme sur le dictionnaire libre Wiktionnaire.

La documentation pour ce module peut être créée à Module:glossaire/Documentation

local m_bases = require("Module:bases")
local m_langs = require("Module:langues")
local m_table = require("Module:table")
local m_string = require("Module:string")
local m_params = require("Module:paramètres")

local p = {}

function p.glossaryNoCat(frame)
  return p.glossary(frame, true)
end

function p.glossary(frame, nocat)
  nocat = nocat or false

  -- Analyse des arguments
  local args = frame:getParent().args

  local tableLen = m_table.length(args)
  if nocat then
    if tableLen < 1 then
      return [[<span style="color:red; font-weight: bold;">Veuillez saisir au moins un glossaire !</span>]] .. m_bases.fait_categorie_contenu("Wiktionnaire:Erreurs d’appel du modèle glossaire")
    end
  else
    if tableLen < 2 then
      return [[<span style="color:red; font-weight: bold;">Veuillez saisir au moins un glossaire et un code langue !</span>]] .. m_bases.fait_categorie_contenu("Wiktionnaire:Erreurs d’appel du modèle glossaire")
    end
  end

  local glossaries = {}
  local last
  local key = args["clé"]
  if key == nil then
    key = ""
  end
  if key ~= "" then
    key = "|" .. key
  end

  for _, arg in ipairs(args) do
    if last ~= nil then
      table.insert(glossaries, last)
    end
    last = arg
  end

  local langCode
  local lang

  if nocat then
    table.insert(glossaries, last)
  else
    langCode = last
    lang = m_langs.get_nom(langCode)
  end

  local text = ""
  local categories = ""

  if not nocat and lang == nil then
    return mw.ustring.format(
        [=[<span style="color:red; font-weight: bold;" title="Code langue saisi : %s">Code langue inconnu !</span>[[Catégorie:Wiktionnaire:Glossaires avec langue manquante]]]=],
        langCode
    )
  end

  local filteredGlossaries = {}

  for _, glossary in ipairs(glossaries) do
  	local cat = "Catégorie:" .. m_bases.ucfirst(glossary) .. " en " .. lang
    table.insert(filteredGlossaries, "[[:" .. cat .. "|" .. glossary .. "]][[" .. cat .. "]]")
  end

  if next(filteredGlossaries) then
  	local glossaireText = "le glossaire"
  	if #filteredGlossaries > 1 then
  		glossaireText = "les glossaires"
  	end
    text = "→ Ce mot est dans " .. glossaireText .. " des " .. table.concat(filteredGlossaries, ", des ") .. "."
  end

  return text
end

return p