Module:HeroData: Difference between revisionsGive feedback
Jump to navigation
Jump to search
m fixed get_ability_key returning ability data instead of the ability data's key |
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'] = | 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"] = localize(hero_key, hero_key) | |||
-- Iterate attribute categories | -- Iterate attribute categories | ||
| Line 243: | Line 232: | ||
-- get label and postfix | -- get label and postfix | ||
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 = | 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 = | 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 = | 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 | ||