Module:Icon: Difference between revisions

Jump to navigation Jump to search
Put the "nowrap" around the icon and text – not just icon, it doesn't do anything that way
LVL (talk | contribs)
Cleaned up the code for displaying the icon text.
Line 58: Line 58:


     local langCode, langData = getLangData()
     local langCode, langData = getLangData()
     local hasOnlyImage = iconData.image and iconData.image ~= "" and not iconData.name and not iconData.key and (iconData.link == nil or iconData.link == "") and customText == ""
   
 
    -- Determine display name with clear priority
    -- Use translation if available
     local displayName = ""
local displayName = (iconData.name or (not hasOnlyImage and name)) or ""
    if customText ~= "" then
if iconData.key and langData[iconData.key] then
        displayName = customText
    displayName = langData[iconData.key]
    elseif iconData.key and langData[iconData.key] then
end
        displayName = langData[iconData.key]
    elseif iconData.name then
        displayName = iconData.name
    elseif iconOnly then
        displayName = ""
    else
        displayName = name  -- fallback to input name
    end


     -- Localize link if on a translated subpage
     -- Localize link if on a translated subpage
Line 77: Line 84:
     end
     end


    local finalText = (customText ~= "") and customText or displayName
     local iconHtml = string.format('<span %s>[[File:%s|%s|link=]]</span>', style, iconData.image, size)
     local iconHtml = string.format('<span %s>[[File:%s|%s|link=]]</span>', style, iconData.image, size)


if iconOnly or displayName == "" then
    if iconOnly or displayName == "" then
    return iconHtml
        return iconHtml
end
    end


     local textHtml = (noLink or link == "") and finalText or string.format('[[%s|%s]]', link, finalText)
     local textHtml = (noLink or link == "") and displayName or string.format('[[%s|%s]]', link, displayName)
     return '<span style="white-space:nowrap;">' .. iconHtml .. " " .. textHtml .. '</span>'
     return '<span style="white-space:nowrap;">' .. iconHtml .. " " .. textHtml .. '</span>'
end
end


return p
return p