Module:HeroData: Difference between revisions

Sur (talk | contribs)
m fixed get_ability_key returning ability data instead of the ability data's key
Sur (talk | contribs)
m shortcut function localize(key, add_space_before_cap(fallback)) now used
Line 5: Line 5:
local util_module = require('Module:Utilities')
local util_module = require('Module:Utilities')
local lang_module = require('Module:Lang')
local lang_module = require('Module:Lang')
local dictionary_module = require('Module:Dictionary')
local attribute_module = require('Module:AttributeData')
local attribute_module = require('Module:AttributeData')


Line 113: Line 114:
template_args = {}
template_args = {}
template_args[1] = lang_module.get_string(item_key, 'en')
template_args[1] = lang_module.get_string(item_key, 'en')
template_args['alt'] = lang_module.get_string(item_key)
template_args['alt'] = localize(item_key, item_key)
local expanded_template = mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args }
local expanded_template = mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args }
str = str .. "* " .. expanded_template .. "\n"
str = str .. "* " .. expanded_template .. "\n"
Line 208: Line 209:
     -- Add the main parameters
     -- Add the main parameters
     template_args["name_english"] = hero_name
     template_args["name_english"] = hero_name
      
     local hero_key = p.get_hero_key(hero_name)
    template_args["name_localized"] = lang_module.get_string(p.get_hero_key(hero_name))
     template_args["name_localized"] = localize(hero_key, hero_key)
   
    local wep_name = hero_data["WeaponName"]
    if (wep_name ~= nil) then template_args["weapon_name"] = lang_module.get_string(wep_name) end
      
    local wep_desc = hero_data["WeaponDescription"]
    if (wep_desc ~= nil) then template_args["weapon_description"] = lang_module.get_string(wep_desc) end
   
    local role = hero_data["Role"]
    if (role ~= nil) then template_args["role"] = lang_module.get_string(role) end
   
    local playstyle = hero_data["Playstyle"]
    if (playstyle ~= nil) then template_args["playstyle"] = lang_module.get_string(playstyle) end
      
      
     -- Iterate attribute categories
     -- Iterate attribute categories
Line 243: Line 232:
-- get label and postfix
-- get label and postfix
label = lang_module.get_string(stat_data["label"])
label = localize(stat_data["label"], stat_name)
postfix = stat_data["postfix"]
postfix = stat_data["postfix"]
if (postfix == nil) then  
if (postfix == nil) then  
Line 340: Line 329:
-- get label and postfix
-- get label and postfix
label = lang_module.get_string(stat_data["label"])
label = localize(stat_data["label"], stat_name)
postfix = stat_data["postfix"]
postfix = stat_data["postfix"]
if (postfix == nil) then  
if (postfix == nil) then  
Line 478: Line 467:
-- Retrieve hero's localized name
-- Retrieve hero's localized name
hero_name = lang_module.get_string(hero_key)
hero_name = localize(hero_key, hero_key)
-- Retrieve hero's english name, used for hero icon
-- Retrieve hero's english name, used for hero icon
Line 569: Line 558:
-- Localize, fallback to attr_key with proper spaces
-- Localize, fallback to attr_key with proper spaces
attr_localized = lang_module.get_string(attr_data["label"])
attr_localized = lang_module.get_string(attr_data["label"])
if (attr_localized == nil) then attr_localized = util_module.add_space_before_cap(attr_key) end
if (attr_localized == nil or attr_localized == "") then attr_localized = util_module.add_space_before_cap(attr_key) end
-- Get postfix
-- Get postfix
Line 579: Line 568:
end
end
else -- If not in attributes data, use key with proper spacing
else -- If not in attributes data, use key with proper spacing
attr_localized = util_module.add_space_before_cap(attr_key)
attr_localized = dictionary_module.translate(attr_key)
end
end
Line 594: Line 583:
return output_str
return output_str
end
end
function localize(key, fallback)
local result = lang_module.get_string(key)
if (result == "") or (result == nil) then
result = util_module.add_space_before_cap(fallback) .. mw.getCurrentFrame():expandTemplate{title="MissingValveTranslationTooltip"}
end
return result
end


-- {{Hero count}} access point
-- {{Hero count}} access point