Module:Lang: Difference between revisions

Jump to navigation Jump to search
fixed error when no label colour assigned
omit empty links in processed inline_attribute tags
Line 68: Line 68:
      
      
     -- 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 class="no-blue-link" style="text-wrap:nowrap; font-weight:bold; color:%s;">%s [[%s|{{#invoke:Lang|get_string|InlineAttribute_%s}}]]</span>',  
        local label_color = replacement.label_color or 'inherit'
            replacement.label_color or 'inherit',  
        local icon = replacement.icon or ''
            replacement.icon,
        local link = replacement.link or ''
            replacement.link,
        -- pre-process string, then check to omit link if the string is empty
            key)
        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
         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 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
         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>'
    return frame:preprocess(text)
     end
end)
 
return frame:preprocess(text)
end
end