Ce module crée les titres des sections de langue des articles du Wiktionnaire. Il est utilisé par le modèle {{langue}}.
sectionLangue()
Construit le titre de section de langue pour le code donné et la liste des catégories appropriées. Si une erreur se produit, une des catégories suivantes sera appliquée :
frame
1
(string) : Le code de langue.nocat
(boolean, optionnel) : Si renseigné, aucune catégorie ne sera ajoutée.La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis la page Module:section langue/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_bases = require("Module:bases")
local m_langues = require("Module:langues")
local m_params = require("Module:paramètres")
local p = {}
--- Format the given language name and code. If a portal for the language exists, a link to it is returned.
--- Else, if a main namespace page with the same title as the language name exists, a link to that page is returned.
--- Otherwise, the passed language name is returned.
--- @param langName string The language name.
--- @param langCode string The language code.
--- @return string The formatted title.
local function getTitleText(langName, langCode)
local langNameUc = m_bases.ucfirst(langName)
if m_langues.hasPortal(langCode) then
return mw.ustring.format("]", langNameUc, langNameUc)
end
-- Do not link to ] as no specific meaning has been established as of 2015-06-22.
if langCode ~= "conv" then
if mw.title.new(langName).exists then
return mw.ustring.format("]", langName, langNameUc)
end
end
return langNameUc
end
--- Get the rare letters categories for the given language code and page title.
--- @param langCode string A language code to get the category’s name from.
--- @param pageTitle string The title of the page to extract characters from.
--- @return table<string> A table containing all relevant rare letter category links.
local function getRareLettersCategories(langCode, pageTitle)
local langData = mw.loadData("Module:langues/lettres_rares")
if not langData or not langData or not langData then
return {}
end
local categories = {}
for i = 1, mw.ustring.len(pageTitle) do
local char = mw.ustring.sub(pageTitle, i, i)
if mw.ustring.find(char, langData) then
-- Special case for "İ" whose lower-case is "i", so we keep it upper-cased
local c = char == "İ" and char or mw.ustring.lower(char)
table.insert(categories, mw.ustring.format(
"]",
c,
m_langues.getName(langCode)
))
end
end
return categories
end
--- Build the full title for the given text, language code and categories.
--- @param text string The title’s text.
--- @param langCode string The language code to use as the `id`.
--- @param categories table<string> The list of categories to append.
--- @return string The formatted title.
local function assembleTitle(text, langCode, categories)
local result = "<span class='sectionlangue'"
if langCode then
result = result .. " id='" .. langCode .. "'"
else
result = result .. " style='color: red; font-style: italic'"
end
return result .. ">" .. text .. "</span>" .. table.concat(categories)
end
--- Build the title for the given language code and page title.
--- @param langCode string The language code to use.
--- @param pageTitle string The title of the page.
--- @param noCat boolean If true, categories will not be appended to the returned title.
--- @return string The formatted title.
local function buildTitle(langCode, pageTitle, noCat)
local langName = m_langues.getName(langCode)
local categories = {}
if not noCat then
table.insert(categories, m_bases.fait_categorie_contenu(langName))
if m_bases.page_de_contenu() then
for _, c in ipairs(getRareLettersCategories(langCode, pageTitle)) do
table.insert(categories, c)
end
end
end
return assembleTitle(getTitleText(langName, langCode), langCode, categories)
end
--- Function used by ].
--- It shows the name of a language and applies relevant categories.
--- Parameters:
--- parent frame.args (string): The language code.
--- parent frame.args (boolean): If true, no categories will be applied.
--- @return string The wikicode.
function p.sectionLangue(frame)
-- Récupération des variables nécessaires à la création du titre
local args, success = m_params.process(frame:getParent().args, {
= { required = true, checker = function(lang)
return m_langues.getName(lang) ~= nil
end },
= { type = m_params.BOOLEAN, default = false },
}, true)
if not success then
local error = args
local message = args
if error == m_params.INVALID_VALUE then
local text = m_bases.ucfirst(frame:getParent().args)
.. ]]=]
local category = { m_bases.fait_categorie_contenu("Wiktionnaire:Sections de langue avec code inconnu") }
return assembleTitle(text, nil, category)
elseif error == m_params.MISSING_PARAM or error == m_params.EMPTY_PARAM then
local text = "]"
local category = { m_bases.fait_categorie_contenu("Wiktionnaire:Sections de langue sans langue précisée") }
return assembleTitle(text, nil, category)
end
return mw.ustring.format("<span>Erreur : %s</span>", message)
.. "]"
end
return buildTitle(args, mw.title.getCurrentTitle().text, args)
end
return p