Module:Traits: Difference between revisions

m
add i18n
No edit summary
m (add i18n)
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
-- pystart
-- pystart
require('Module:CommonFunctions')
require('Module:CommonFunctions')
local i18n = require('Module:I18n')
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local getTranslations = i18n.getTranslations
local p = {}
local p = {}


-- Main process
-- Main process
function p.main(frame)
function p.main(frame)
     local args = getArgs(frame);
     local args = getArgs(frame)
     local is_rose = args[1] == 'Rose' and args.ecp == 'true';
    local tr = getTranslations(frame, 'Template:Traits', args.lang, true)
     local is_rose = args[1] == 'Rose' and args.ecp == 'true'
 
    function translate(key)
        return i18n.translate(tr, key)
    end


     -- Argument init
     -- Argument init
Line 22: Line 29:


     -- Dictionary for headers
     -- Dictionary for headers
     local prop = { 'MP Usage', 'Cooldown', 'Duration', 'MP Recovery', 'Max Hits', 'Effects' }
     local prop = {  
    if is_rose then
        is_rose and translate('ECP Usage') or translate('MP Usage'),
         for k, v in ipairs(prop) do
        translate('Cooldown'),
            prop[k] = v:gsub('MP', 'ECP')
        translate('Duration'),
        end
        is_rose and translate('ECP Recovery') or translate('MP Recovery'),
     end
        translate('Max Hits'),
         translate('Effects'),
     }


     local prop_short = { 'mp', 'cd', 'duration', 'mp_recovery', 'hits', 'effects', 'chance' }
     local prop_short = { 'mp', 'cd', 'duration', 'mp_recovery', 'hits', 'effects', 'chance' }
    local OPTIONS = {
        lang_suffix = args.lang and ('/' .. args.lang) or '',
        lang_append = args.lang ~= nil and args.lang ~= ''
    }


     local STR = {
     local STR = {
Line 44: Line 58:
         POWERFUL = 'Powerful',
         POWERFUL = 'Powerful',
         USEFUL = 'Useful',
         USEFUL = 'Useful',
         SEC = ' Seconds',
         SEC = 'Seconds',
         MP = ' MP',
         MP = 'MP',
         ECP = ' ECP'
         ECP = 'ECP',
        PERSISTENT = 'Persistent',
        PERSISTENT2 = 'Persistent2'
     }
     }


     local details = { { STR.LIGHT, STR.CRITICAL, STR.REVERSED },
     local details = {
         { STR.HEAVY, STR.HASTE,    STR.REGEN2,  STR.RUTHLESS, STR.POWERFUL, STR.REVERSED }, { STR.KB1 },
        { STR.LIGHT, STR.CRITICAL, STR.REVERSED },
         { STR.REGEN1 }, { STR.USEFUL }, {STR.KB2} }
         { STR.HEAVY, STR.HASTE,    STR.REGEN2,  STR.RUTHLESS, STR.POWERFUL, STR.REVERSED },
        { STR.KB1 },
         { STR.REGEN1 },
        { STR.USEFUL, STR.PERSISTENT2 },
        { STR.KB2 }
    }


     -- Default values
     -- Default values
Line 62: Line 83:
         },
         },
         [STR.CRITICAL] = {
         [STR.CRITICAL] = {
             mp = (args['def_ignore1'] or args['def_ignore2']) and 100 or 120
             mp = (args['def_ignore1'] ~= nil or args['def_ignore2'] ~= nil) and 100 or 120
         },
         },
         [STR.HASTE] = {
         [STR.HASTE] = {
Line 87: Line 108:
         [STR.USEFUL] = {
         [STR.USEFUL] = {
             dmg = 80
             dmg = 80
        },
        [STR.PERSISTENT2] = {
            dmg = 100
         }
         }
     }
     }
Line 126: Line 150:
         tr4 = new_row()
         tr4 = new_row()
         -- Add indicator headers
         -- Add indicator headers
         tr1:tag('th'):wikitext('Mode'):attr('rowspan', 2)
         tr1:tag('th'):wikitext(translate('Mode')):attr('rowspan', 2)
         tr3:tag('td'):wikitext(frame:expandTemplate {
         tr3:tag('td'):wikitext(frame:expandTemplate {
             title = 'PvE'
             title = translate('PvE')
         })
         })
         tr4:tag('td'):wikitext(frame:expandTemplate {
         tr4:tag('td'):wikitext(frame:expandTemplate {
             title = 'PvP'
             title = translate('PvP')
         })
         })
     end
     end
Line 137: Line 161:
     -- Loop through 2 input traits.
     -- Loop through 2 input traits.
     for trait_count, trait_name in ipairs(traits) do
     for trait_count, trait_name in ipairs(traits) do
         local th = tr1:tag('th'):wikitext(trait_name:gsub('Persistent2', 'Persistent') .. ' ' .. skill);
         local th = tr1:tag('th'):wikitext(trait_name:gsub(translate(STR.PERSISTENT) .. 2, translate(STR.PERSISTENT)) .. ' ' .. skill);
         local th_effect;
         local th_effect;
         local th_skilltext;
         local th_skilltext;
Line 145: Line 169:
         for detail_key, detail in ipairs(details) do
         for detail_key, detail in ipairs(details) do
             if not th_effect then
             if not th_effect then
                 th_effect = tr2:tag('th'):wikitext('Attribute Effect');
                 th_effect = tr2:tag('th'):wikitext(translate('Attribute Effect'));
             end
             end
             if indexOf(trait_name, detail) then
             if indexOf(trait_name, detail) then
                 local th_detail = tr2:tag('th'):wikitext(prop[detail_key]);
                 local th_detail = tr2:tag('th'):wikitext(translate(prop[detail_key]));
                 th:attr('colspan', tonumber(th:getAttr('colspan') or 1) + 1)
                 th:attr('colspan', tonumber(th:getAttr('colspan') or 1) + 1)
             end
             end
Line 169: Line 193:
             if not th_skilltext then
             if not th_skilltext then
                 th_skilltext = tr3:tag('td'):attr('rowspan', has_pvp_values and 2 or 1):wikitext(frame:expandTemplate {
                 th_skilltext = tr3:tag('td'):attr('rowspan', has_pvp_values and 2 or 1):wikitext(frame:expandTemplate {
                     title = 'SkillText',
                     title = translate('SkillText'),
                     args = {
                     args = {
                         trait_name,
                         trait_name,
Line 209: Line 233:
                             suffix = STR.SEC
                             suffix = STR.SEC
                         end
                         end
                        suffix = suffix and (' ' .. suffix) or ''


                         local base_detail = args[short_detail_improved .. modeSuffix]
                         local base_detail = args[short_detail_improved .. modeSuffix]
Line 214: Line 239:
                         local function calcEndValue(base)
                         local function calcEndValue(base)
                             local end_value;
                             local end_value;
                             if tonumber(short_detail) ~= nil then
                             if base and tonumber(base) == nil then
                                 end_value = base or -1
                                 end_value = base
                             else
                             else
                                 end_value = (tonumber(multiplier) / 100) * tonumber(base or -1)
                                 end_value = (tonumber(multiplier) / 100) * tonumber(base or -1)
Line 232: Line 257:
                                 title = 'Tt',
                                 title = 'Tt',
                                 args = { calcEndValue(enhanced_detail) .. "'''",
                                 args = { calcEndValue(enhanced_detail) .. "'''",
                                     "Final Enhanced Skill" }
                                     translate("Final Enhanced Skill") }
                             }
                             }
                         end
                         end