Ce module définit une fonction permettant d’afficher la table des flexions des noms communs en letton.
generateNounTable
Retourne le wikicode pour le modèle Modèle:lv-nom. Le cas particulier de suns au génitif singulier, qui fait suņa au lieu de suns, est codé en dur dans la fonction.
frame
1
(chaine, optionnel) : Le nominatif singulier du nom à afficher. Si non spécifié, le titre de la page est utilisé.décl
(entier, obligatoire) : Le numéro de la déclinaison.vs-complet
(boolean, optionnel) : Si true
, le vocatif singulier sera affiché dans sa forme complète, sinon il sera affiché sans (radical seul).palatale
(chaine, optionnel) : La consonne palatale à utiliser pour les mutations au génitif et pluriel (dépend de la déclinaison).remplacer
(booléen, optionnel) : Si true
et palatale
est renseigné, la consonne palatale remplacera la dernière lettre du radical au lieu d’être inserée après celle-ci.mode
(chaine, optionnel) : La valeur sing
affichera uniquement le singulier, tandis que la valeur plur
affichera uniquement le pluriel.ns
(chaine, optionnel) : Permet de spécifier le nominatif singulier.np
(chaine, optionnel) : Permet de spécifier le nominatif pluriel.ls
pour le locatif singulier.La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis la page Module:letton-déclinaisons/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.
local m_params = require("Module:paramètres")
local m_bases = require("Module:bases")
local m_table = require("Module:table")
local bit32 = require("bit32")
local DECLENSIONS = mw.loadData("Module:letton-déclinaisons/data")
local SINGULAR = 1
local PLURAL = 2
local NO_DECL_ERROR = "no_declension_for_key"
local USELESS_PARAM_ERROR = "useless_param"
local p = {}
--- Mutate the given root.
--- @param root string The root to modify.
--- @param modify boolean If true, the `modifierLetter` will replace the letter before the suffix, otherwise it will be inserted after it.
--- @param palatal string|nil The palatal letter that will modify the one preceding the suffix. Leave `nil` to keep it.
--- @return string The mutated root.
local function mutate(root, modify, palatal)
if modify then
return mw.ustring.sub(root, 1, -2) .. palatal
end
return root .. palatal
end
local DECl_TITLES = {
"Première", "Deuxième", "Troisième", "Quatrième", "Cinquième", "Sixième"
}
local CASE_NAMES = {
n = "Nominatif",
a = "Accusatif",
g = "Génitif",
d = "Datif",
i = "Instrumental",
l = "Locatif",
v = "Vocatif",
}
local DISPLAY_ORDER = { "n", "a", "g", "d", "i", "l", "v" }
--- Generate the wikicode for the given noun forms.
--- @param forms table The noun forms.
--- @param declension number The declension number (1-6).
--- @param numberMode number A number indicating whether to show the singular only, plural only, or both.
--- @return string The generated wikicode.
local function generateNounTable(forms, declension, numberMode)
local showSing = bit32.band(numberMode, SINGULAR) ~= 0
local showPlur = bit32.band(numberMode, PLURAL) ~= 0
if not showSing and not showPlur then
error("Invalid 'numberMode' value: " .. tostring(numberMode))
end
local code = mw.ustring.format('{| class="wikitable flextable"\n|+ %s déclinaison\n|-\n|', DECl_TITLES)
if showSing then
code = code .. "\n| Singulier"
end
if showPlur then
code = code .. "\n| Pluriel"
end
for _, case in ipairs(DISPLAY_ORDER) do
local flexions = forms
code = code .. mw.ustring.format("\n|-\n! %s", CASE_NAMES)
if showSing then
code = code .. "\n|" .. m_bases.lien_modele(flexions, "lv", nil, nil, true)
end
if showPlur then
code = code .. "\n|" .. m_bases.lien_modele(flexions, "lv", nil, nil, true)
end
end
code = code .. "\n|}"
return code
end
--- Generate all forms for the given noun.
--- @param word string The nominative singular form of the noun.
--- @param declension number The declension number (1-6).
--- @param modify boolean If true, the `modifierLetter` will replace the letter before the suffix, otherwise it will be inserted after it.
--- @param palatal string|nil The palatal letter that will modify the one preceding the suffix. Leave `nil` to keep it.
--- @param vocativeKeepsEnding boolean Whether to keep the last letter of the vocative for the 1st, 5th, and 6th declensions.
--- @param specifiedForms table A table specifying values to use for different cases instead of default ones.
--- @return table A table containing all forms of the word.
local function generateNounForms(word, declension, modify, palatal, vocativeKeepsEnding, specifiedForms)
local key = tostring(declension)
if declension == 2 or declension == 3 then
key = key .. "-" .. mw.ustring.sub(word, -2)
else
key = key .. "-" .. mw.ustring.sub(word, -1)
end
local decl = DECLENSIONS
if not decl then
error({ message = NO_DECL_ERROR, key = key })
end
if modify and not palatal then
error({ message = USELESS_PARAM_ERROR, param = "remplacer" })
end
if vocativeKeepsEnding and not decl.vsMayDropEnding then
error({ message = USELESS_PARAM_ERROR, param = "vs-complet" })
end
local root = mw.ustring.sub(word, 1, -mw.ustring.len(decl.endings.n) - 1)
local forms = {}
local anyPalatal = false
for case, endings in pairs(decl.endings) do
local sing = root .. endings
local plur = root .. endings
if palatal and endings.palatal and m_table.length(endings.palatal) ~= 0 then
local mutatedRoot = mutate(root, modify, palatal)
if m_table.contains(endings.palatal, 1) then
sing = mutatedRoot .. endings
anyPalatal = true
end
if m_table.contains(endings.palatal, 2) then
plur = mutatedRoot .. endings
anyPalatal = true
end
end
if case == "v" and not vocativeKeepsEnding and decl.vsMayDropEnding then
sing = root
end
-- Special case for "suns" for the genitive singular
if word == "suns" and declension == 2 and case == "g" then
sing = "suņa"
end
forms = { specifiedForms or sing, specifiedForms or plur }
end
if palatal and not anyPalatal then
error({ message = USELESS_PARAM_ERROR, param = "palatale" })
end
return forms
end
local function errorMessage(message)
return mw.ustring.format("<span style='color: red'>%s</span>]", message)
end
function p.generateNounTable(frame)
local spec = {
= {},
= { required = true, type = m_params.INT, checker = function(decl)
return decl >= 1 and decl <= 6
end },
= { type = m_params.BOOLEAN, default = false },
= {},
= { type = m_params.BOOLEAN, default = false },
= { enum = { "sing", "plur" }, default = nil },
}
for case, _ in pairs(CASE_NAMES) do
spec = {}
spec = {}
end
local args, validArgs = m_params.process(frame:getParent().args, spec, true) -- Silent errors
if not validArgs then
return errorMessage(mw.ustring.format(
"Paramètre « %s » incorrect : %s",
tostring(args),
args
))
end
local pageTitle = mw.title.getCurrentTitle().text
local word = args or pageTitle
local declension = args
local vocativeKeepsEnding = args
local palatal = args
local modify = args
local numberMode
if args == "sing" then
numberMode = SINGULAR
elseif args == "plur" then
numberMode = PLURAL
else
numberMode = bit32.bor(SINGULAR, PLURAL)
end
local specifiedForms = {}
for case, _ in pairs(CASE_NAMES) do
local keySing = case .. "s"
specifiedForms = args
local keyPlur = case .. "p"
specifiedForms = args
end
local success, data = pcall(function()
local forms = generateNounForms(word, declension, modify, palatal, vocativeKeepsEnding, specifiedForms)
local text = generateNounTable(forms, declension, numberMode)
-- If args is specified, we are most likely on a flexion page, so no categorization
-- But if the current page corresponds to the nominative plural and the mode is plural only, do categorize
if not args or (pageTitle == forms.n and numberMode == PLURAL) then
local catName = mw.ustring.format("Noms communs de la %s déclinaison en letton", mw.ustring.lower(DECl_TITLES))
text = text .. m_bases.fait_categorie_contenu(catName)
end
return text
end)
if not success then
if data.message == NO_DECL_ERROR then
return errorMessage("Déclinaison incorrecte : " .. tostring(declension))
elseif data.message == USELESS_PARAM_ERROR then
return errorMessage(mw.ustring.format("Paramètre « %s » superflu, veuillez le retirer.", data.param))
end
return errorMessage("Une erreur est survenue : " .. tostring(data))
end
return data
end
return p