Module:Lang: Difference between revisions

No edit summary
Added replacement of keybind tags with keybind strings
Line 88: Line 88:
      
      
     -- Process panel tags
     -- Process panel tags
text = text:gsub('<Panel class=\"AbilityPropertyIcon prop_(.-)\">', function(key)
text = text:gsub('<Panel class=\"AbilityPropertyIcon prop_(.-)\">', function(key)
     local replacement = replacements[key]
    local replacement = replacements[key]
    if replacement then
    if replacement then
        local label_color = replacement.label_color or 'inherit'
        local label_color = replacement.label_color or 'inherit'
        local icon = replacement.icon or ''
        local icon = replacement.icon or ''
        local link = replacement.link or ''
        local link = replacement.link or ''
        -- pre-process string, then check to omit link if the string is empty
        -- pre-process string, then check to omit link if the string is empty
        local translated = frame:preprocess('{{#invoke:Lang|get_string|InlineAttribute_' .. key .. '}}')
        local translated = frame:preprocess('{{#invoke:Lang|get_string|InlineAttribute_' .. key .. '}}')
       
       
        if translated == '' then
        if translated == '' then
            return string.format('<span class="no-blue-link" style="text-wrap:nowrap; font-weight:bold; color:%s;">%s</span>', label_color, icon)
            return string.format('<span class="no-blue-link" style="text-wrap:nowrap; font-weight:bold; color:%s;">%s</span>', label_color, icon)
        else
        else
            return string.format('<span class="no-blue-link" style="text-wrap:nowrap; font-weight:bold; color:%s;">%s [[%s|%s]]</span>',  
            return string.format('<span class="no-blue-link" style="text-wrap:nowrap; font-weight:bold; color:%s;">%s [[%s|%s]]</span>',
                label_color,  
                label_color,
                icon,  
                icon,
                link,  
                link,
                translated)
                translated)
        end
        end
    else
    else
        return '<span style="color:red;font-weight:bold;border-bottom:1px dotted red;" title="Missing attribute definition - Add \''..key..'\' to local replacements in [Module:Lang]">['..key..']</span>'
        return '<span style="color:red;font-weight:bold;border-bottom:1px dotted red;" title="Missing attribute definition - Add \''..key..'\' to local replacements in [Module:Lang]">['..key..']</span>'
    end
    end
end)
end)
   
     -- Process citadel_inline_attribute tags
text = text:gsub("{g:citadel_inline_attribute:'(.-)'}", function(key)
    local replacement = replacements[key]
    if replacement then
        local label_color = replacement.label_color or 'inherit'
        local icon = replacement.icon or ''
        local link = replacement.link or ''
        -- pre-process string, then check to omit link if the string is empty
        local translated = frame:preprocess('{{#invoke:Lang|get_string|InlineAttribute_' .. key .. '}}')
       
        if translated == '' then
            return string.format('<span class="no-blue-link" style="text-wrap:nowrap; font-weight:bold; color:%s;">%s</span>', label_color, icon)
        else
            return string.format('<span class="no-blue-link" style="text-wrap:nowrap; font-weight:bold; color:%s;">%s [[%s|%s]]</span>',  
                label_color,  
                icon,  
                link,  
                translated)
        end
    else
        return '<span style="color:red;font-weight:bold;border-bottom:1px dotted red;" title="Missing attribute definition - Add \''..key..'\' to local replacements in [Module:Lang]">['..key..']</span>'
    end
end)
 
    KEYBINDS = {
    Attack = '{{Mouse|1}}',
    ADS = '{{Mouse|2}}',
    AltCast = '{{Mouse|3}}',
    Reload = 'R',
    Roll = 'Shift',
    Mantle = 'Space',
    Crouch = 'Ctrl',
    AbilityMelee = 'Melee',
    Ability1 = '1',
    Ability2 = '2',
    Ability3 = '3',
    Ability4 = '4',
    MoveDown = 'Down',
    MoveForward = 'Forward',
    }
      
      
     -- Process citadel_inline_attribute tags
     -- Process citadel_binding/citadel_keybind tags to replace with keybind strings/templates
text = text:gsub("{g:citadel_inline_attribute:'(.-)'}", function(key)
text = text:gsub("{g:citadel_binding:'(.-)'}", function(key)
    local replacement = replacements[key]
    local replacement = KEYBINDS[key]
    if replacement then
    if replacement then
        local label_color = replacement.label_color or 'inherit'
        return replacement
        local icon = replacement.icon or ''
    else
        local link = replacement.link or ''
        return '<span style="color:red;font-weight:bold;border-bottom:1px dotted red;" title="Missing keybind - Add \''..key..'\' to local replacements in [Module:Lang]">['..key..']</span>'
        -- pre-process string, then check to omit link if the string is empty
    end
        local translated = frame:preprocess('{{#invoke:Lang|get_string|InlineAttribute_' .. key .. '}}')
end)
       
        if translated == '' then
text = text:gsub("{g:citadel_keybind:'(.-)'}", function(key)
            return string.format('<span class="no-blue-link" style="text-wrap:nowrap; font-weight:bold; color:%s;">%s</span>', label_color, icon)
local replacement = KEYBINDS[key]
        else
    if replacement then
            return string.format('<span class="no-blue-link" style="text-wrap:nowrap; font-weight:bold; color:%s;">%s [[%s|%s]]</span>',
        return replacement
                label_color,
    else
                icon,
        return '<span style="color:red;font-weight:bold;border-bottom:1px dotted red;" title="Missing keybind - Add \''..key..'\' to local replacements in [Module:Lang]">['..key..']</span>'
                link,
    end
                translated)
end)
        end
    else
        return '<span style="color:red;font-weight:bold;border-bottom:1px dotted red;" title="Missing attribute definition - Add \''..key..'\' to local replacements in [Module:Lang]">['..key..']</span>'
    end
end)


return frame:preprocess(text)
return frame:preprocess(text)
end
end