Module:ClassNav: Difference between revisions
From Heroes of Might and Magic: Olden Era Official Wiki
Undo revision 21129 by 76561198256426587 (talk) |
No edit summary |
||
| Line 53: | Line 53: | ||
table.insert(html, "|}") | table.insert(html, "|}") | ||
-- Débogage : Affiche ce que Cargo voit pour un ID suspect | |||
local debug_test = mw.ext.cargo.query("Translation", "type", {where = "target_id = 'wiki_might'", limit = 1}) | |||
if #debug_test > 0 then | |||
table.insert(html, "<tr><td>Debug: Type trouvé pour wiki_might est " .. debug_test[1].type .. "</td></tr>") | |||
else | |||
table.insert(html, "<tr><td>Debug: AUCUNE donnée trouvée pour wiki_might !</td></tr>") | |||
end | |||
return table.concat(html, "\n") | return table.concat(html, "\n") | ||
end | end | ||
return p | return p | ||
Revision as of 10:15, 31 May 2026
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;"'}
-- 1. Titre "Classes" (utilisation de wiki_hero_class ou wiki_classes)
-- J'utilise wiki_hero_class comme tu l'as indiqué
local title = getTrans("wiki_hero_class", lang, "hero_infobox") or "Classes"
table.insert(html, '! colspan=10 style="text-align:center; letter-spacing:.3px;"| ' .. title)
-- Fonction interne modifiée pour utiliser les nouveaux IDs
local function addRow(category_id, class_type, label_id)
table.insert(html, "|-")
-- 2. Label dynamique (Force ou Magie)
local label = getTrans(label_id, lang, "common") or label_id
table.insert(html, "! style='width:8em;'| " .. label)
local classes = mw.ext.cargo.query("HeroClass", "id", {where = "class_type = '" .. class_type .. "'"})
for _, c in ipairs(classes) do
local name_translated = getTrans(c.id, lang, "hero_class") or c.id
local name_en = getTrans(c.id, 'en', 'hero_class') or c.id
local file_name = name_en:gsub("%s+", "_")
table.insert(html, string.format('| style="display:inline-block; border:0px;"| [[File:%s.png|30px|link=%s/%s]] [[%s/%s|%s]]',
file_name, name_en, lang, name_en, lang, name_translated))
end
end
-- 3. Appel avec les bons IDs de traduction
addRow("might_heroes", "might", "wiki_might")
addRow("magic_heroes", "magic", "wiki_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, "|}")
-- Débogage : Affiche ce que Cargo voit pour un ID suspect
local debug_test = mw.ext.cargo.query("Translation", "type", {where = "target_id = 'wiki_might'", limit = 1})
if #debug_test > 0 then
table.insert(html, "<tr><td>Debug: Type trouvé pour wiki_might est " .. debug_test[1].type .. "</td></tr>")
else
table.insert(html, "<tr><td>Debug: AUCUNE donnée trouvée pour wiki_might !</td></tr>")
end
return table.concat(html, "\n")
end
return p


