La documentation pour ce module peut être créée à Module:thématique/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 = {}
local tree = mw.loadData("Module:thématique/data")
local lexiconTree = mw.loadData("Module:lexique/data")
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 ] .. m_bases.fait_categorie_contenu("Wiktionnaire:Erreurs d’appel du modèle thématique")
end
else
if tableLen < 2 then
return ] .. m_bases.fait_categorie_contenu("Wiktionnaire:Erreurs d’appel du modèle thématique")
end
end
local glossaries = {}
local last
local key = args
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.getName(langCode)
end
local text = ""
local categories = ""
if not nocat and lang == nil then
return mw.ustring.format(
]]=],
langCode
)
end
local filteredGlossaries = {}
for _, glossary in ipairs(glossaries) do
local cat = "Catégorie:" .. m_bases.ucfirst(glossary) .. " en " .. lang
local text = "]"
if mw.title.getCurrentTitle().namespace == 0 then
text = text .. "]"
end
table.insert(filteredGlossaries, text)
end
if next(filteredGlossaries) then
text = "→ Ce mot est dans "
if #filteredGlossaries == 1 then
text = text .. "la thématique des " .. filteredGlossaries .. "."
else
text = text .. "les thématiques "
for i=1,#filteredGlossaries do
text = text .. "des " .. filteredGlossaries
if i == #filteredGlossaries -1 then
text = text .. " et "
elseif i < #filteredGlossaries then
text = text .. ", "
else
text = text .. "."
end
end
end
end
return text
end
local function parseThematicTitle(title, langCode)
local pattern = "(.+) en (.+)"
local langCat, subjectCat, lang, subject
subject, lang = mw.ustring.match(title, pattern)
-- Récupérer le code à partir du nom de la langue
if langCode == nil then
langCode = m_langs.getLanguageCode(lang)
end
if lang ~= nil and subject ~= nil then
langCat = "Thématiques en " .. lang .. "|" .. subject
-- subjectCat = subject .. "|" .. lang
subjectCat = subject .. "|" .. (m_langs.getSortKey(langCode) or "")
end
return langCat, subjectCat, lang, langCode, subject
end
function p.categorizeThematic(frame)
local args = m_params.process(frame:getParent().args, {
= {}
})
local langCode = args
local title = mw.title.getCurrentTitle().text
local langCat, lexiconCat, lang, langCode, subject = parseThematicTitle(title, langCode)
local lowerSubject = mw.ustring.lower(subject)
if langCat and lexiconCat and lang and langCode and subject then
local header = ""
if tree then
header = mw.ustring.format(
] qui sont des ].
%s
Pour ajouter une entrée à cette catégorie, vous pouvez utiliser le modèle <code>{{]|%s|%s}}</code>.
]=],
lang, lowerSubject, tree, lowerSubject, langCode
)
if tree ~= nil then
for _, v in pairs(tree) do
-- Si la super catégorie commence par le même mot-clé, enlever ce préfixe de la clé
-- Exemple : 'droit romain' est sous 'droit', donc la clé est 'romain'
header = header .. mw.ustring.format(
"]",
v, lang, subject
)
if not tree then
header = header .. "]"
end
end
end
if tree ~= nil then
for _, v in pairs(tree) do
if lexiconTree then
-- Si la super catégorie commence par le même mot-clé, enlever ce préfixe de la clé
-- Exemple : 'droit romain' est sous 'droit', donc la clé est 'romain'
header = header .. mw.ustring.format(
"]",
lang, lexiconTree, v, lowerSubject
)
else
header = header .. "]"
end
end
end
else
header = "]"
end
return header .. mw.ustring.format("]]", langCat, m_bases.ucfirst(lexiconCat))
else
return "]"
end
end
return p