Module:Damage: Difference between revisions

no edit summary
m (Add i18n support)
No edit summary
 
(7 intermediate revisions by one other user not shown)
Line 12: Line 12:
     local tr = getTranslations(frame, 'Template:Damage', args.lang, true)
     local tr = getTranslations(frame, 'Template:Damage', args.lang, true)
     local out
     local out
   
 
     function translate(key)
     function translate(key)
         return i18n.translate(tr, key)
         return i18n.translate(tr, key)
Line 24: Line 24:


     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 59: Line 58:
         do_table = args[1] == 'true',
         do_table = args[1] == 'true',
         character = args[2] or args.char or 'Elsword',
         character = args[2] or args.char or 'Elsword',
        lang_suffix = args.lang and ('/' .. args.lang) or '',
        lang_append = args.lang ~= nil and args.lang ~= '',
         format = args.format ~= 'false',
         format = args.format ~= 'false',
         no_max = args.no_max == 'true',
         no_max = args.no_max == 'true',
Line 99: Line 100:
         {
         {
             key = '',
             key = '',
             name = 'Normal',
             name = translate('Normal'),
             value = 1
             value = 1
         },
         },
         {
         {
             key = 'enhanced',
             key = 'enhanced',
             name = 'Enhanced (Trait)',
             name = translate('Enhanced (Trait)'),
             value = args.enhanced ~= nil and 0.8
             value = args.enhanced ~= nil and 0.8
         },
         },
         {
         {
             key = 'empowered',
             key = 'empowered',
             name = 'Empowered',
             name = translate('Empowered'),
             value = args.empowered == 'true' and 1.2 or tonumber(args.empowered) or false
             value = args.empowered == 'true' and 1.2 or tonumber(args.empowered) or false
         },
         },
         {
         {
             key = 'useful',
             key = 'useful',
             name = 'Useful',
             name = translate('Useful'),
             value = (args.hits_useful or args.avg_hits_useful) and (args.useful_penalty or args.useful or 0.8) or false
             value = (args.hits_useful or args.avg_hits_useful) and (args.useful_penalty or args.useful or 0.8) or false
         },
         },
         {
         {
             key = 'heavy',
             key = 'heavy',
             name = 'Heavy',
             name = translate('Heavy'),
             value = args.heavy ~= nil and 1.44
             value = args.heavy ~= nil and 1.44
         }
         }
Line 139: Line 140:
             |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 passive_title = v .. OPTIONS.lang_suffix
             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")
             local passive_values = split(is_custom and v or
             local passive_values = split(is_custom and v or
                 frame:preprocess('{{:' .. passive_name .. '}}{{#arrayprint:' .. passive_name .. '}}'));
                 frame:preprocess('{{:' .. passive_name .. '}}{{#arrayprint:' .. passive_name .. '}}'));
            local display_title


            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
             elseif OPTIONS.lang_append then
                 --[[
                 --[[
                 Translate page's display title to passive name.
                 Translate page's display title to passive name.
                 Customized will override this name, thus no need to perform the translation
                 Customized will override this name, thus no need to perform the translation
                 --]]
                 --]]
                 local translated_page = mw.title.makeTitle('', passive_title)
                 display_title = i18n.getTranslatedTitle(passive_title)
                if translated_page.exists then
                    display_title = string.match(translated_page:getContent(), "%{%{DISPLAYTITLE:([^}]-)%}%}")
                end
             end
             end


Line 171: Line 168:
                 exist = frame:preprocess('{{#ifexist:' .. passive_name .. '|true|false}}') == 'true'
                 exist = frame:preprocess('{{#ifexist:' .. passive_name .. '|true|false}}') == 'true'
             }
             }
         elseif not string.find(v, '[a-hj-zA-HJ-Z]+') then
         elseif string.match(v, '^[()+%-*/%d%s,.i]+$') then
             --[[
             --[[
             Change how args are received.
             Change how args are received.
Line 425: Line 422:
                             hit_count = hit_count == '' and 1 or hit_count
                             hit_count = hit_count == '' and 1 or hit_count
                             new_value.hit_counts[damage_type][k] = hit_count *
                             new_value.hit_counts[damage_type][k] = hit_count *
                                 ((string.find(damage_key, 'awk_') and args.awk_count) and args.awk_count[1] or args.count[1])
                                 ((string.find(damage_key, 'awk') and args.awk_count) and args.awk_count[1] or args.count[1])
                         end
                         end
                     end)
                     end)
Line 711: Line 708:
             text = { translate('Regular'), (function()
             text = { translate('Regular'), (function()
                 if OPTIONS.dmp then
                 if OPTIONS.dmp then
                     return link('Dynamo Point System', 'Dynamo Configuration', args.awk_prefix,
                     return link('Dynamo Point System' .. OPTIONS.lang_suffix, 'Dynamo Configuration', args.awk_prefix,
                     OPTIONS.dmp ~= 'false' and ('(' .. OPTIONS.dmp .. ' DMP)') .. (args.awk_suffix and (' ' .. args.awk_suffix) or '' ))
                     OPTIONS.dmp ~= 'false' and (fillTemplate('({1} DMP)', { OPTIONS.dmp })) .. (args.awk_suffix and (' ' .. args.awk_suffix) or ''))
                 elseif args.awk_alias then
                 elseif args.awk_alias then
                     return link(args.awk_alias[1], args.awk_alias[2], args.awk_prefix, args.awk_suffix)
                     return link(args.awk_alias[1], args.awk_alias[2], args.awk_prefix, args.awk_suffix)
                 end
                 end
                 return link('Awakening Mode', nil, args.awk_prefix, args.awk_suffix)
                 return link('Awakening Mode' .. OPTIONS.lang_suffix, translate('Awakening Mode'), args.awk_prefix, args.awk_suffix)
             end)()
             end)()
             },
             },
Line 752: Line 749:
             text = {
             text = {
                 (inArgs('count') and not OPTIONS.use_avg) and
                 (inArgs('count') and not OPTIONS.use_avg) and
                 (table.concat({ 'Per', args.count_name or 'Group' }, ' ')) or
                 (fillTemplate(translate('Per {1}'), { args.count_name or translate('Group') })) or
                 translate('Average'),
                 translate('Average'),
                 translate('Max')
                 translate('Max')
Line 895: Line 892:
     function doContentByMode(mode)
     function doContentByMode(mode)
         local mode_row = TABLE:new()
         local mode_row = TABLE:new()
         mode_row:tag('td'):wikitext(frame:expandTemplate { title = mode })
         mode_row:tag('td'):wikitext(frame:expandTemplate { title = translate(mode) })
         local damage_entries = returnDamageInOrder()
         local damage_entries = returnDamageInOrder()
         local last_number
         local last_number
Line 945: Line 942:
     if OPTIONS.bug then
     if OPTIONS.bug then
         bug = frame:expandTemplate {
         bug = frame:expandTemplate {
             title = 'SkillText',
             title = translate('SkillText'),
             args = { 'FreeTraining' }
             args = { 'FreeTraining' }
         }
         }