Module:Icon: Difference between revisions

Jump to navigation Jump to search
No edit summary
LVL (talk | contribs)
Link ability icons directly to their specific section headers instead of the general Abilities section.
Line 51: Line 51:
end
end


-- Build localized anchor (#Abilities)
-- Get the translated name (Moved up so getLink can use it)
local function getLocalizedAnchor(key, fallback, langCode)
    local anchor = fallback
 
    if langCode ~= "en" and key then
        local translated = lang_module.get_string(key, langCode, fallback)
        if type(translated) == "string" then
            anchor = translated:gsub("<[^>]+>", "")
        end
    end
 
    anchor = anchor:gsub(" ", "_")
    return anchor
end
 
-- Infer link from type and available fields
local function getLink(iconInfo, langCode)
    if iconInfo.type == "ability" then
        local hero = iconInfo.hero_name or iconInfo.name
        -- Data:Lang en.json
        local anchor = getLocalizedAnchor("guide_basics_abilities_header", "Abilities", langCode)
        return hero .. "#" .. anchor
    end
 
    return linkOverrides[iconInfo.name] or iconInfo.name
end
 
local function getTranslatedName(iconInfo, langCode)
local function getTranslatedName(iconInfo, langCode)
     if langCode == "en" then
     if langCode == "en" then
Line 108: Line 82:
     -- No valid key > fallback
     -- No valid key > fallback
     return iconInfo.name
     return iconInfo.name
end
-- Infer link from type and available fields
local function getLink(iconInfo, langCode)
    if iconInfo.type == "ability" then
        local hero = iconInfo.hero_name or iconInfo.name
       
        -- Get the translated name for the specific ability
        local abilityName = getTranslatedName(iconInfo, langCode)
       
        -- Format for URL: replace spaces with underscores
        local anchor = abilityName:gsub(" ", "_")
       
        return hero .. "#" .. anchor
    end
    return linkOverrides[iconInfo.name] or iconInfo.name
end
end