Editing Module:Icon

Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 17: Line 17:
local lang_codes = mw.loadJsonData("Data:LangCodes.json")
local lang_codes = mw.loadJsonData("Data:LangCodes.json")
local lang_module = require("Module:Lang")
local lang_module = require("Module:Lang")
local table_data = require("Module:Icon/data")
local table_data = require("Module:IconSandbox/data")


local cachedLangCode
local cachedLangCode
Line 51: Line 51:
end
end


-- Get the translated name
-- Build localized anchor (#Abilities)
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 63: Line 89:


         if type(translated) == "string" then
         if type(translated) == "string" then
             return (translated:gsub("<[^>]+>", ""))
             return translated:gsub("<[^>]+>", "")
         end
         end


Line 82: Line 108:
     -- 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


Line 119: Line 128:
     if not iconInfo then
     if not iconInfo then
         return name
         return name
    end
-- Quick hack: ability names are used by MediaWiki:Gadget-infobox-tooltip.js and expected to be localized
    local langCode = getLangCode()
    if iconInfo.type == "ability" then
        return getTranslatedName(iconInfo, langCode)
     end
     end


Line 206: Line 208:
         style = 'class="module-icon-ability" style="position:relative; bottom:2px;"'
         style = 'class="module-icon-ability" style="position:relative; bottom:2px;"'
     else
     else
         style = 'class="c-icon" style="position:relative; bottom:2px;"'
         style = 'style="position:relative; bottom:2px;"'
     end
     end


Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Deadlock:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template

Pages included on this page: