Module:Damage: Difference between revisions

Add lang support for multi-lang title dealing
m (Undo revision 918091 by Boxsnake (talk))
Tag: Undo
(Add lang support for multi-lang title dealing)
Line 17: Line 17:


     local modes = { 'PvE', 'PvP' }
     local modes = { 'PvE', 'PvP' }
    local langSuffix = args.lang and ('/' .. args.lang) or ''


     -- Define the schema for the table
     -- Define the schema for the table
Line 131: Line 132:
             |passive1=... |passive2=... -> { passive1, passive2 }
             |passive1=... |passive2=... -> { passive1, passive2 }
             --]]
             --]]
            local is_translated = langSuffix ~= nil and langSuffix ~= ''
             local passive_name = v
             local passive_name = v
            local passive_title = v .. langSuffix
             local is_custom = string.find(k, '_define') ~= nil
             local is_custom = string.find(k, '_define') ~= nil
             local passive_index = string.match(k, "%d")
             local passive_index = string.match(k, "%d")
Line 137: Line 140:
                 frame:preprocess('{{:' .. passive_name .. '}}{{#arrayprint:' .. passive_name .. '}}'));
                 frame:preprocess('{{:' .. passive_name .. '}}{{#arrayprint:' .. passive_name .. '}}'));


            local display_title
             if is_custom then
             if is_custom then
                 passive_name = passive_values[#passive_values]
                 passive_name = passive_values[#passive_values]
                 passive_values[#passive_values] = nil
                 passive_values[#passive_values] = nil
            elseif is_translated then
                --[[
                Translate page's display title to passive name.
                Customized will override this name, thus no need to perform the translation
                --]]
                local translated_page = mw.title.makeTitle('', passive_title)
                if translated_page.exists then
                    display_title = string.match(translated_page:getContent(), "%{%{DISPLAYTITLE:([^}]-)%}%}")
                end
             end
             end


Line 146: Line 159:
                 value = passive_values[1],
                 value = passive_values[1],
                 value_pvp = passive_values[2],
                 value_pvp = passive_values[2],
                 alias = args['alias' .. passive_index] or (passive_index == OPTIONS.append_index and OPTIONS.append_name),
                 alias = args['alias' .. passive_index] or (passive_index == OPTIONS.append_index and OPTIONS.append_name) or display_title,
                 suffix = args['suffix' .. passive_index] and (' ' .. args['suffix' .. passive_index]) or '',
                 suffix = args['suffix' .. passive_index] and (' ' .. args['suffix' .. passive_index]) or '',
                 prefix = args['prefix' .. passive_index] and (args['prefix' .. passive_index] .. ' ') or '',
                 prefix = args['prefix' .. passive_index] and (args['prefix' .. passive_index] .. ' ') or '',