Module:fr-flexion2

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

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

--==============================================================================
--
-- Module:fr-flexion2
--
--     Génération des boites de flexions pour la langue française,
--     utilisé par le Modèle:fr-flexion
--
-- écrit par:  Maëlan (inspiré du Module:fr-flexion écrit par GaAs fin 2014)
-- date:       2024-02
-- licence:    CC-BY-SA 3.0
--
--==============================================================================

-- les bibliothèques dont on dépend:
Params = require('Module:paramètres')
Pron = require('Module:prononciation')

-- notre module:
local M = {}

-- les «types» de flexions supportés par le modèle:
local types = {
  --[".e.s"] = { "", "s", "e", "es", "", "", "", "" },
  [".e.s"] = { ms="", mp="s", fs="e", fp="es",
               pron_ms="", pron_mp="", pron_fs="", pron_fp="" },
  --["in.e.s"] = { "in", "ins", "ine", "ines", "ɛ̃", "ɛ̃", "in", "in" },
  ["in.e.s"] = { ms="in", mp="ins", fs="ine", fp="ines",
                 pron_ms="ɛ̃", pron_mp="ɛ̃", pron_fs="in", pron_fp="in" },
  --["ain.e.s"] = { "ain", "ains", "aine", "aines", "ɛ̃", "ɛ̃", "ɛn", "ɛn" },
  ["ain.e.s"] = { ms="ain", mp="ains", fs="aine", fp="aines",
                  pron_ms="ɛ̃", pron_mp="ɛ̃", pron_fs="ɛn", pron_fp="ɛn" },
  --["er.e.s"] = { "er", "ers", "ère", "ères", "e", "e", "ɛʁ", "ɛʁ" },
  ["er.e.s"] = { ms="er", mp="ers", fs="ère", fp="ères",
                 pron_ms="e", pron_mp="e", pron_fs="ɛʁ", pron_fp="ɛʁ" },
  -- TODO
}

local liste_noms_types = {}
for nom, _ in pairs(types) do
  table.insert(liste_noms_types, nom)
end

-- teste si une chaine se termine par une autre chaine
-- (cf https://stackoverflow.com/a/72921992 ):
function string:endswith(suffix)
  return self:sub(-#suffix) == suffix
end

-- génère un message d’erreur en Wikicode:
function erreur(msg)
  -- TODO:
  local txt = '<strong class="error">Usage erroné de {{modèle|fr-flexion}} : '
  txt = txt .. msg
  txt = txt .. '</strong>'
  txt = txt .. "[[Catégorie:Appels de modèles incorrects/fr-flexion]]"
  return txt
end

-- fonction d’entrée, invoquée par [[Modèle:fr-flexion]]:
function M.boite_flexions(frame)
  local args = Params.process(frame:getParent().args, {
    ["type"] = { enum = liste_noms_types },
    [1] = { alias_of = "type" },
    ["termi.ms"] = {},
    ["termi.mp"] = {},
    ["termi.fs"] = {},
    ["termi.fp"] = {},
    ["pron.termi.ms"] = {},
    ["pron.termi.mp"] = {},
    ["pron.termi.fs"] = {},
    ["pron.termi.fp"] = {},
    ["pron.ms"] = {},
    ["pron.mp"] = {},
    ["pron.fs"] = {},
    ["pron.fp"] = {},
    ["pronh"] = { enum = {"non", "muet", "aspiré"}, default="non" },
    ["vedette"] = { default = mw.title.getCurrentTitle().text },
  })
  -- pré-remplit les paramètres en fonction du type de flexion:
  if args["type"] ~= nil then
    local t = types[args["type"]]
    args["termi.ms"] = t.ms
    args["termi.mp"] = t.mp
    args["termi.fs"] = t.fs
    args["termi.fp"] = t.fp
    args["pron.termi.ms"] = t.pron_ms
    args["pron.termi.mp"] = t.pron_mp
    args["pron.termi.fs"] = t.pron_fs
    args["pron.termi.fp"] = t.pron_fp
  end
  -- extrait la prononciation du radical:
  local pron_radic = nil
  if args["pron.ms"] ~= nil then
    if not args["pron.ms"]:endswith(args["termi.ms"]) then
      return erreur("pron.ms ne se termine pas comme attendu")
    end
    pron_radic = args["pron.ms"]:sub(1, -#args["termi.ms"]-1)
  end
  if args["pron.mp"] ~= nil then
    if not args["pron.mp"]:endswith(args["termi.mp"]) then
      return erreur("pron.mp ne se termine pas comme attendu")
    end
    if pron_radic == nil then
      pron_radic = args["pron.mp"]:sub(1, -#args["termi.mp"]-1)
    elseif args["pron.mp"] ~= pron_radic .. args["termi.mp"] then
      return erreur("plusieurs prononciations contradictoires")
    end
  end
  if args["pron.fs"] ~= nil then
    if not args["pron.fs"]:endswith(args["termi.fs"]) then
      return erreur("pron.fs ne se termine pas comme attendu")
    end
    if pron_radic == nil then
      pron_radic = args["pron.fs"]:sub(1, -#args["termi.fs"]-1)
    elseif args["pron.fs"] ~= pron_radic .. args["termi.fs"] then
      return erreur("plusieurs prononciations contradictoires")
    end
  end
  if args["pron.fp"] ~= nil then
    if not args["pron.fp"]:endswith(args["termi.fp"]) then
      return erreur("pron.fp ne se termine pas comme attendu")
    end
    if pron_radic == nil then
      pron_radic = args["pron.fp"]:sub(1, -#args["termi.fp"]-1)
    elseif args["pron.fp"] ~= pron_radic .. args["termi.fp"] then
      return erreur("plusieurs prononciations contradictoires")
    end
  end
  -- TODO:
  return ""
end

-- publication de notre module:
return M