Module:Lang: Difference between revisions

Jump to navigation Jump to search
refactored process_html_tags function to insert variables into a single style template
Added coloured hyperlinks to inline attribute tags
Line 39: Line 39:
      
      
     local replacements = {
     local replacements = {
        SpiritIcon = {icon='{{Icon/Purple|[[File:AttributeIconTechShieldHealth.png|link=Spirit Damage|12px]]}}'},
    SpiritIcon = {icon='{{Icon/Purple|[[File:AttributeIconTechShieldHealth.png|link=Spirit Damage|12px]]}}', link='Spirit Damage'},
        SpiritDamage = {icon='{{Icon/Purple|[[File:AttributeIconTechShieldHealth.png|link=Spirit Damage|12px]]}}', label_color='#bc8ee8'},
    SpiritDamage = {icon='{{Icon/Purple|[[File:AttributeIconTechShieldHealth.png|link=Spirit Damage|12px]]}}', label_color='#bc8ee8', link='Spirit Damage'},
        SpiritResist = {icon='{{Icon/Purple|[[File:Spirit_Armor.png|link=Damage_Resistance|20px]]}}', label_color='#bc8ee8'},
    SpiritResist = {icon='{{Icon/Purple|[[File:Spirit_Armor.png|link=Damage_Resistance|20px]]}}', label_color='#bc8ee8', link='Damage_Resistance'},
        FireRate = {icon='{{Icon/White|[[File:Fire_Rate.png|link=Fire Rate|20px]]}}', label_color='#ffefd7'},
    FireRate = {icon='{{Icon/White|[[File:Fire_Rate.png|link=Fire Rate|20px]]}}', label_color='#ffefd7', link='Fire Rate'},
        ReducedFireRate = {icon='{{Icon/White|[[File:Fire_Rate.png|link=Fire Rate|20px]]}}', label_color='#ffefd7'},
    ReducedFireRate = {icon='{{Icon/White|[[File:Fire_Rate.png|link=Fire Rate|20px]]}}', label_color='#ffefd7', link='Fire Rate'},
        MeleeDamage = {icon='{{Icon/Brown|[[File:Melee damage.png|link=Melee Damage|20px]]}}', label_color='#ec981a'},
    MeleeDamage = {icon='{{Icon/Brown|[[File:Melee damage.png|link=Melee Damage|20px]]}}', label_color='#ec981a', link='Melee Damage'},
        WeaponDamage = {icon='{{Icon/Brown|[[File:Damage.png|link=Weapon Damage|20px]]}}', label_color='#ec981a'},
    WeaponDamage = {icon='{{Icon/Brown|[[File:Damage.png|link=Weapon Damage|20px]]}}', label_color='#ec981a', link='Weapon Damage'},
        BulletResist = {icon='{{Icon/Brown|[[File:Bullet_Armor.png|link=Damage_Resistance|20px]]}}', label_color='#ec981a'},
    BulletResist = {icon='{{Icon/Brown|[[File:Bullet_Armor.png|link=Damage_Resistance|20px]]}}', label_color='#ec981a', link='Damage_Resistance'},
        BonusWeaponDamage = {icon='{{Icon/Brown|[[File:Damage.png|link=Weapon Damage|20px]]}}', label_color='#ec981a'},
    BonusWeaponDamage = {icon='{{Icon/Brown|[[File:Damage.png|link=Weapon Damage|20px]]}}', label_color='#ec981a', link='Weapon Damage'},
        MoveSpeed = {icon='{{Icon/White|[[File:Move_speed.png|link=Move speed|20px]]}}', label_color='#ffefd7'},
    MoveSpeed = {icon='{{Icon/White|[[File:Move_speed.png|link=Move speed|20px]]}}', label_color='#ffefd7', link='Move speed'},
        BonusSpiritDamage = {icon='{{Icon/Purple|[[File:AttributeIconTechShieldHealth.png|link=Spirit Damage|12px]]}}', label_color='#bc8ee8'},
    BonusSpiritDamage = {icon='{{Icon/Purple|[[File:AttributeIconTechShieldHealth.png|link=Spirit Damage|12px]]}}', label_color='#bc8ee8', link='Spirit Damage'},
        BonusFireRate = {icon='{{Icon/White|[[File:Fire_Rate.png|link=Fire Rate|20px]]}}', label_color='#ffefd7'},
    BonusFireRate = {icon='{{Icon/White|[[File:Fire_Rate.png|link=Fire Rate|20px]]}}', label_color='#ffefd7', link='Fire Rate'},
        Heal = {icon='{{Icon/Green|[[File:Health_regen.png|link=Health_Regen|20px]]}}', label_color='#13f278'},
    Heal = {icon='{{Icon/Green|[[File:Health_regen.png|link=Health_Regen|20px]]}}', label_color='#13f278', link='Health_Regen'},
        BonusMoveSpeed = {icon='{{Icon/White|[[File:Move_speed.png|link=Move speed|20px]]}}', label_color='#ffefd7'},
    BonusMoveSpeed = {icon='{{Icon/White|[[File:Move_speed.png|link=Move speed|20px]]}}', label_color='#ffefd7', link='Move speed'},
        Spirit = {icon='{{Icon/NoColor|[[File:Spirit_icon.png|link=Spirit Power|20px]]}}', label_color='#bc8ee8'},
    Spirit = {icon='{{Icon/NoColor|[[File:Spirit_icon.png|link=Spirit Power|20px]]}}', label_color='#bc8ee8', link='Spirit Power'},
        Stun = {icon='{{Icon/White|[[File:Status_Stun.png|link=Stun|20px]]}}'},
    Stun = {icon='{{Icon/White|[[File:Status_Stun.png|link=Stun|20px]]}}', link='Stun'},
        SpiritDPS = {icon='{{Icon/Purple|[[File:AttributeIconTechShieldHealth.png|link=Spirit Damage|12px]]}}', label_color='#bc8ee8'},
    SpiritDPS = {icon='{{Icon/Purple|[[File:AttributeIconTechShieldHealth.png|link=Spirit Damage|12px]]}}', label_color='#bc8ee8', link='Spirit Damage'},
    Healing = {icon='{{Icon/Green|[[File:Health_regen.png|link=Healing|20px]]}}', label_color='#13f278'},
    Healing = {icon='{{Icon/Green|[[File:Health_regen.png|link=Healing|20px]]}}', label_color='#13f278', link='Healing'},
    Regen = {icon='{{Icon/Green|[[File:Health_regen.png|link=Health_Regen|20px]]}}', label_color='#13f278'},
    Regen = {icon='{{Icon/Green|[[File:Health_regen.png|link=Health_Regen|20px]]}}', label_color='#13f278', link='Health_Regen'},
    Slow = {icon='{{Icon/White|[[File:MoveSlow.png|link=Movement_Slow|20px]]}}', label_color='#ffefd7'},
    Slow = {icon='{{Icon/White|[[File:MoveSlow.png|link=Movement_Slow|20px]]}}', label_color='#ffefd7', link='Movement_Slow'},
    SlowResistance = {icon='{{Icon/White|[[File:MoveSlow.png|link=Movement_Slow#Movement_Slow_Resist|20px]]}}', label_color='#ffefd7'},
    SlowResistance = {icon='{{Icon/White|[[File:MoveSlow.png|link=Movement_Slow#Movement_Slow_Resist|20px]]}}', label_color='#ffefd7', link='Movement_Slow#Movement_Slow_Resist'},
    }
}
    
    
    -- Process HTML spans
    text = text:gsub('<span class="highlight">(.-)</span>', "<span style= font-weight:bold>%1</span>")
    text = text:gsub('<span class="diminish">(.-)</span>', '<span style="font-style: italic;color:#C0C0C0">%1</span>')
    text = text:gsub('<span class=".-">(.-)</span>', '%1')
   
     -- Process citadel_inline_attribute tags
     -- Process citadel_inline_attribute tags
     text = text:gsub("{g:citadel_inline_attribute:'(.-)'}", function(key)
     text = text:gsub("{g:citadel_inline_attribute:'(.-)'}", function(key)
     local replacement = replacements[key]
     local replacement = replacements[key]
         if replacement then
         if replacement then
             return string.format('<span style="text-wrap:nowrap; font-weight:bold; color:%s">%s {{#invoke:Lang|get_string|InlineAttribute_%s}}</span>', replacement.label_color, replacement.icon, key)
             return string.format('<span class="no-blue-link" style="text-wrap:nowrap; font-weight:bold; color:%s;">%s [[%s|{{#invoke:Lang|get_string|InlineAttribute_%s}}]]</span>', replacement.label_color, replacement.icon, replacement.link, key)
         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>'
Line 72: Line 77:
     end)
     end)
      
      
    -- Process HTML spans
    text = text:gsub('<span class="highlight">(.-)</span>', "<span style= font-weight:bold>%1</span>")
    text = text:gsub('<span class="diminish">(.-)</span>', '<span style="font-style: italic;color:#C0C0C0">%1</span>')
    text = text:gsub('<span class=".-">(.-)</span>', '%1')
     return frame:preprocess(text)
     return frame:preprocess(text)
end
end