Module:ClassNav
From Heroes of Might and Magic: Olden Era Official Wiki
Documentation for this module may be created at Module:ClassNav/doc
local p = {}
-- Fonction utilitaire pour récupérer une traduction
local function getTrans(target_id, lang, type, field)
field = field or "name"
if not target_id or target_id == "" then return nil end
local query = mw.ext.cargo.query("Translation", field, {
where = string.format("target_id = '%s' AND language = '%s' AND type = '%s'", target_id, lang, type),
limit = 1
})
if not query or #query == 0 then
query = mw.ext.cargo.query("Translation", "name", {
where = string.format("target_id = '%s' AND language = 'en' AND type = '%s'", target_id, type),
limit = 1
})
end
return (query and #query > 0) and query[1][field] or nil
end
function p.render(frame)
local lang = frame.args.language or mw.title.getCurrentTitle().text:match("/(%a%a)$") or "en"
local html = {'{| class="wikitable" style="width:100%; text-align:left;"'}
-- Titre
table.insert(html, '! colspan=10 style="text-align:center; letter-spacing:.3px;"| ' .. (getTrans("wiki_classes", lang, "ui") or "Classes"))
-- Fonction interne pour créer les lignes
local function addRow(category_id, hero_type)
table.insert(html, "|-")
table.insert(html, "! style='width:8em;'| " .. (getTrans(category_id, lang, "ui") or category_id))
-- Requête pour lister les classes (ajuste le WHERE selon ton schéma Cargo)
local classes = mw.ext.cargo.query("HeroClass", "id", {where = "type = '" .. hero_type .. "'"})
for _, c in ipairs(classes) do
local name = getTrans(c.id, lang, "hero_class") or c.id
table.insert(html, string.format('| style="display:inline-block; border:0px;"| [[File:%s.png|30px|link=%s/%s]] [[%s/%s|%s]]',
c.id, c.id, lang, c.id, lang, name))
end
end
addRow("might_heroes", "might")
addRow("magic_heroes", "magic")
table.insert(html, "|-")
table.insert(html, '| colspan=10 style="text-align: center;"| [[Heroes/' .. lang .. '|' .. (getTrans("all_heroes", lang, "ui") or "Tous les Héros") .. ']]')
table.insert(html, "|}")
return table.concat(html, "\n")
end
return p


