Module:HeroSpecializationData
This module allows for the dynamic extraction of variables, asset icons, and translations for hero specializations stored within the wiki's Cargo database (specifically from the HeroSpecialization and Translation tables). It automatically handles localized fallback to English if a translation in the requested language is missing.
Basic Syntax
To fetch a data field, use the following syntax:
{{#invoke:HeroSpecializationData|get|SPEC_ID|VARIABLE|LANGUAGE_CODE}}
SPEC_ID: The technical identifier of the specialization (e.g.,dungeon_hero_3_specialization).VARIABLE: The keyword for the specific data field you want to display (see the list below).LANGUAGE_CODE: (Optional) The localization code (e.g.,en,fr,pt_br). Defaults to English (en).
---
Available Variables
📝 Text & Translations (Language-Dependent)
These variables query the Translation table using the type="hero_specialization" filter and dynamically adapt to the requested language code.
| Variable | Description | Example Output (fr) |
|---|---|---|
name |
The localized name of the specialization. | Frappe venimeuse |
description |
The localized description detailing exact combat modifiers, formula math, and passive scaling behaviors. | Son coup héroïque inflige +10 point(s) de dégâts... |
🎨 Assets & Technical Properties
Technical variables mapped out in the core specialization table (queried from the HeroSpecialization table).
| Variable | Description | Example Output |
|---|---|---|
icon |
The exact filename string used for the specialization asset. | dungeon_hero_3_specialization_icon
|
source_path |
The file path location of the original data dump JSON. | DB/heroes_specializations/specializations_dungeon.json
|
---
Practical Examples
Example 1: Fetching Localized Names and Descriptions
To display the French name and description for the hero 3 dungeon specialization:
'''{{#invoke:HeroSpecializationData|get|dungeon_hero_3_specialization|name|fr}}'''<br>
{{#invoke:HeroSpecializationData|get|dungeon_hero_3_specialization|description|fr}}
Output:
Frappe venimeuse
Son coup héroïque inflige +10 point(s) de dégâts (+5 tous les 6 niveau(x) de héros). De plus, il empoisonne la cible...
Example 2: Complete Template Row Automatic Link Integration
If you are displaying a row from a main hero context page and have access to the hero's specialization_id variable:
[[File:{{#invoke:HeroSpecializationData|get|{{{specialization_id}}}|icon}}.png|64px]]
'''{{#invoke:HeroSpecializationData|get|{{{specialization_id}}}|name|{{{lang|en}}}}}'''
local p = {}
-- Table de correspondance entre les noms usuels de classes et les identifiants Cargo des spécialisations
local class_mapping = {
["herald"] = "magic_demon",
["warlock"] = "magic_dungeon",
["cleric"] = "magic_human",
["druid"] = "magic_nature",
["necromancer"] = "magic_undead",
["riftspeaker"] = "magic_unfrozen",
["enforcer"] = "might_demon",
["overlord"] = "might_dungeon",
["knight"] = "might_human",
["warden"] = "might_nature",
["death knight"]= "might_undead",
["oathkeeper"] = "might_unfrozen"
}
-- Fonction interne pour traduire le nom usuel en identifiant Cargo valide
local function get_cargo_spec_id(input_id)
if not input_id then return "" end
-- On nettoie les espaces inutiles et on passe tout en minuscules
local clean_id = mw.text.trim(string.lower(input_id))
-- Si le nom est dans notre dictionnaire, on renvoie l'ID Cargo, sinon on garde l'original
return class_mapping[clean_id] or clean_id
end
-- Fonction locale pour mettre la première lettre de chaque mot en majuscule
-- Gère les mots séparés par des espaces ou des underscores (_)
local function capitalize(str)
if not str then return "" end
-- Remplace la première lettre de chaque mot par sa version majuscule
local capitalized = str:gsub("(%a)([%w]*)", function(first, rest)
return first:upper() .. rest:lower()
end)
return capitalized
end
-- Fonction principale pour récupérer une donnée de spécialisation
-- Syntaxe : {{#invoke:HeroSpecializationData|get|ID_SPECIALISATION|CHAMP|LANGUE}}
function p.get(frame)
local args = frame.args[1] and frame.args or frame:getParent().args
-- Conversion automatique du nom de classe saisi vers le format de la base de données
local spec_id = get_cargo_spec_id(args[1])
local field = args[2]
local lang = args[3] or 'en' -- Anglais par défaut
if spec_id == "" or not field then
return "Erreur : ID de spécialisation ou champ manquant."
end
-- 1. Gestion des champs textuels traduits (name, description)
if field == 'name' or field == 'description' then
local queryOpts = {
where = string.format('target_id="%s" AND language="%s" AND type="hero_specialization"', spec_id, lang)
}
local res = mw.ext.cargo.query('Translation', field, queryOpts)
if res and res[1] and res[1][field] then
return res[1][field]
else
-- Système de secours (fallback) vers l'anglais
if lang ~= 'en' then
local fallbackOpts = {
where = string.format('target_id="%s" AND language="en" AND type="hero_specialization"', spec_id)
}
local fallbackRes = mw.ext.cargo.query('Translation', field, fallbackOpts)
if fallbackRes and fallbackRes[1] and fallbackRes[1][field] then
return fallbackRes[1][field]
end
end
return ""
end
end
-- 2. Gestion des données brutes de la table "HeroSpecialization"
local specOpts = {
where = string.format('id="%s"', spec_id)
}
local specRes = mw.ext.cargo.query('HeroSpecialization', field, specOpts)
if specRes and specRes[1] and specRes[1][field] then
local value = specRes[1][field]
-- SI le champ demandé est l'icône, on applique la transformation des majuscules
if field == 'icon' then
return capitalize(value)
end
return value
end
return ""
end
return p


