Difference between revisions of "Module:Availability/Sandbox"

From Team Fortress Wiki
Jump to: navigation, search
Line 9: Line 9:
 
-- Expands the template Tooltip for a given pair of values.
 
-- Expands the template Tooltip for a given pair of values.
 
function tooltip(tool, tip)
 
function tooltip(tool, tip)
return frame:expandTemplate{title='Tooltip', args={tool, tip}}
+
  return frame:expandTemplate{title='Tooltip', args={tool, tip}}
 
end
 
end
  
 
-- Expands the template Item name for a given value.
 
-- Expands the template Item name for a given value.
 
function item_name(arg)
 
function item_name(arg)
return frame:expandTemplate{title='Item name', args={arg}}
+
  return frame:expandTemplate{title='Item name', args={arg}}
 
end
 
end
  
 
-- Expands the template Common string for a given value. Note that some common string values include an additional parameter, here called opt_arg.
 
-- Expands the template Common string for a given value. Note that some common string values include an additional parameter, here called opt_arg.
 
function common_string(arg, opt_arg)
 
function common_string(arg, opt_arg)
return frame:expandTemplate{title='Common string', args={arg, opt_arg}}
+
  return frame:expandTemplate{title='Common string', args={arg, opt_arg}}
 
end
 
end
  
 
-- Returns ' (text)', with correct parenthesis characters in Chinese.
 
-- Returns ' (text)', with correct parenthesis characters in Chinese.
 
function paren(text)
 
function paren(text)
if if_lang == '/zh_hans' or if_lang == '/zh-hant' then
+
  if if_lang == '/zh_hans' or if_lang == '/zh-hant' then
return ' (' .. text .. ')'
+
    return ' (' .. text .. ')'
else
+
  else
return ' (' .. text .. ')'
+
    return ' (' .. text .. ')'
end
+
  end
 
end
 
end
  
 
-- Replaces the old Dictionary/templatecore strings
 
-- Replaces the old Dictionary/templatecore strings
lookup = {
+
lookup = {
-- Singleton strings (without a number)
+
  -- Singleton strings (without a number)
['audition-reel'] = function() return '[[Mann Co. Supply Crate/Seriesless_crates' .. if_lang .. '#Audition Reel|' .. common_string('audition reel') .. ']]' end,
+
  ['audition-reel'] = function() return '[[Mann Co. Supply Crate/Seriesless_crates' .. if_lang .. '#Audition Reel|' .. common_string('audition reel') .. ']]' end,
['australium'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' .. paren('[[Australium weapons' .. if_lang .. '|' .. common_string('australium') .. ']]') end,
+
  ['australium'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' .. paren('[[Australium weapons' .. if_lang .. '|' .. common_string('australium') .. ']]') end,
['botkiller'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' .. paren('[[Botkiller weapons' .. if_lang .. '|' .. common_string('botkiller') .. ']]') end,
+
  ['botkiller'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' .. paren('[[Botkiller weapons' .. if_lang .. '|' .. common_string('botkiller') .. ']]') end,
['bread-box'] = function() return '[[Bread Box' .. if_lang .. '|' .. item_name('bread box') .. ']]' .. paren('[[Unique' .. if_lang .. '|' .. item_name('unique') .. ']] ' .. common_string('and') .. ' [[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
+
  ['bread-box'] = function() return '[[Bread Box' .. if_lang .. '|' .. item_name('bread box') .. ']]' .. paren('[[Unique' .. if_lang .. '|' .. item_name('unique') .. ']] ' .. common_string('and') .. ' [[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
['chemistryset'] = function() return '[[Chemistry Set' .. if_lang .. '|' .. item_name('chemistry set') .. ']]' end,
+
  ['chemistryset'] = function() return '[[Chemistry Set' .. if_lang .. '|' .. item_name('chemistry set') .. ']]' end,
['collectors'] = function() return '[[Chemistry Set' .. if_lang .. '|' .. item_name('chemistry set') .. ']]' .. paren('[[Collectors' .. if_lang .. '|' .. item_name('collector\'s') .. ']]') end,
+
  ['collectors'] = function() return '[[Chemistry Set' .. if_lang .. '|' .. item_name('chemistry set') .. ']]' .. paren('[[Collectors' .. if_lang .. '|' .. item_name('collector\'s') .. ']]') end,
['contract'] = function() return '[[ConTracker' .. if_lang .. '#Contracts|' .. common_string('contract') .. ']]' .. paren('[[Unique' .. if_lang .. '|' .. item_name('unique') .. ']] ' .. common_string('and') .. ' [[Decorated' .. if_lang .. '|' .. item_name('decorated') .. ']]') end,
+
  ['contract'] = function() return '[[Gun Mettle Campaign' .. if_lang .. '#Contracts|' .. common_string('contract') .. ']]' .. paren('[[Decorated' .. if_lang .. '|' .. item_name('decorated') .. ']]') end,
['craft'] = function() return '[[Crafting' .. if_lang .. '|' .. common_string('craft') .. ']]' end,
+
  ['contract-unique'] = function() return '[[ConTracker' .. if_lang .. '|' .. common_string('contracker') .. ']]' .. paren('[[Unique' .. if_lang .. '|' .. item_name('unique') .. ']]') end,
['crate-scorched'] = function() return '[[Mann Co. Supply Crate/Retired series' .. if_lang .. '#46|' .. common_string('uncrate') .. ' #46]]' .. paren(common_string('scorched')) end,
+
  ['craft'] = function() return '[[Crafting' .. if_lang .. '|' .. common_string('craft') .. ']]' end,
['creepy-crate'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Unlocked Creepy Crates|' .. item_name('unlocked creepy crate') .. ']]' end,
+
  ['crate-scorched'] = function() return '[[Mann Co. Supply Crate/Retired series' .. if_lang .. '#46|' .. common_string('uncrate') .. ' #46]]' .. paren(common_string('scorched')) end,
['directors'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Director\'s Cut|' .. common_string('director\'s cut') .. ']]' end,
+
  ['creepy-crate'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Unlocked Creepy Crates|' .. item_name('unlocked creepy crate') .. ']]' end,
['distributed'] = function() return common_string('distributed') end,
+
  ['directors'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Director\'s Cut|' .. common_string('director\'s cut') .. ']]' end,
['drop'] = function() return '[[Item drop system' .. if_lang .. '|' .. common_string('drop') .. ']]' end,
+
  ['distributed'] = function() return common_string('distributed') end,
['gift-cauldron'] = function() return '[[Halloween Gift Cauldron' .. if_lang .. '|' .. item_name('halloween gift cauldron') .. ']]' end,
+
  ['drop'] = function() return '[[Item drop system' .. if_lang .. '|' .. common_string('drop') .. ']]' end,
['halloween-purchase'] = function() return '[[Mann Co. Store' .. if_lang .. '|' .. tooltip(common_string('purchase'), common_string('purchase-halloween')) .. ']]' end,
+
  ['gift-cauldron'] = function() return '[[Halloween Gift Cauldron' .. if_lang .. '|' .. item_name('halloween gift cauldron') .. ']]' end,
['hauntedgift'] = function() return '[[Haunted Halloween Gift' .. if_lang .. '|' .. item_name('haunted halloween gift') .. ']]' end,
+
  ['halloween-purchase'] = function() return '[[Mann Co. Store' .. if_lang .. '|' .. tooltip(common_string('purchase'), common_string('purchase-halloween')) .. ']]' end,
                ['keyless-crate'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Unlocked Cosmetic Crates|' .. item_name('unlocked cosmetic crate') .. ']]' .. paren('[[Unique' .. if_lang .. '|' .. item_name('unique') .. ']] ' .. common_string('and') .. ' [[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
+
  ['hauntedgift'] = function() return '[[Haunted Halloween Gift' .. if_lang .. '|' .. item_name('haunted halloween gift') .. ']]' end,
['mannup'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' end,
+
  ['keyless-crate'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Unlocked Cosmetic Crates|' .. item_name('unlocked cosmetic crate') .. ']]' .. paren('[[Unique' .. if_lang .. '|' .. item_name('unique') .. ']] ' .. common_string('and') .. ' [[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
['mvm-both-types'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' .. paren('[[Botkiller weapons' .. if_lang .. '|' .. common_string('botkiller') .. ']] ' .. common_string('and') .. ' [[Australium weapons' .. if_lang .. '|' .. common_string('australium') .. ']]') end,
+
  ['mannup'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' end,
['mvm'] = function() return '[[Mann vs. Machine' .. if_lang .. '|' .. common_string('mvm reward') .. ']]' end,
+
  ['mvm-both-types'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' .. paren('[[Botkiller weapons' .. if_lang .. '|' .. common_string('botkiller') .. ']] ' .. common_string('and') .. ' [[Australium weapons' .. if_lang .. '|' .. common_string('australium') .. ']]') end,
['promotional'] = function() return '[[Promotional items' .. if_lang .. '|' .. common_string('promotional') .. ']]' end,
+
  ['mvm'] = function() return '[[Mann vs. Machine' .. if_lang .. '|' .. common_string('mvm reward') .. ']]' end,
['purchase'] = function() return '[[Mann Co. Store' .. if_lang .. '|' .. common_string('purchase') .. ']]' end,
+
  ['promotional'] = function() return '[[Promotional items' .. if_lang .. '|' .. common_string('promotional') .. ']]' end,
['retired'] = function() return common_string('retired') end,
+
  ['purchase'] = function() return '[[Mann Co. Store' .. if_lang .. '|' .. common_string('purchase') .. ']]' end,
['stock'] = function() return '[[Stock weapons' .. if_lang .. '|' .. mw.getContentLanguage():ucfirst(item_name('stock')) .. ']]' end,
+
  ['retired'] = function() return common_string('retired') end,
['stockpile'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Stockpile|' .. common_string('stockpile crate') .. ']]' end,
+
  ['stock'] = function() return '[[Stock weapons' .. if_lang .. '|' .. mw.getContentLanguage():ucfirst(item_name('stock')) .. ']]' end,
['strangifier'] = function() return '[[Strangifier' .. if_lang .. '|' .. item_name('strangifier') .. ']]' .. paren('[[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
+
  ['stockpile'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Stockpile|' .. common_string('stockpile crate') .. ']]' end,
['trade-up'] = function() return '[[Trade-Up' .. if_lang .. '|' .. common_string('trade-up') .. ']]' end,
+
  ['strangifier'] = function() return '[[Strangifier' .. if_lang .. '|' .. item_name('strangifier') .. ']]'.. paren('[[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
['transmute'] = function() return '[[Halloween Transmute' .. if_lang .. '|' .. common_string('halloween transmute') .. ']] ' .. paren('[[Trading' .. if_lang .. '|' .. 'Untradable]]') end,
+
  ['trade-up'] = function() return '[[Trade-Up' .. if_lang .. '|' .. common_string('trade-up') .. ']]' end,
['unavailable'] = function() return common_string('unavailable') end,
+
  ['transmute'] = function() return '[[Halloween Transmute' .. if_lang .. '|' .. common_string('halloween transmute') .. ']] ' .. paren('[[Trading' .. if_lang .. '|' .. common_string('Untradable') .. ']]') end,
['unlock'] = function() return '[[Achievement items' .. if_lang .. '|' .. common_string('unlock') .. ']]' end,
+
  ['unavailable'] = function() return common_string('unavailable') end,
['unusual'] = function() return '[[Mann Co. Supply Crate' .. if_lang .. '|' .. common_string('uncrate') .. ']]' .. paren('[[Unusual' .. if_lang .. '|' .. item_name('unusual') .. ']]') end,
+
  ['unlock'] = function() return '[[Achievement items' .. if_lang .. '|' .. common_string('unlock') .. ']]' end,
 
+
  ['unusual'] = function() return '[[Mann Co. Supply Crate' .. if_lang .. '|' .. common_string('uncrate') .. ']]' .. paren('[[Unusual' .. if_lang .. '|' .. item_name('unusual') .. ']]') end,
-- Multipart strings (with a number)
+
    -- Multipart strings (with a number)
['xmas'] = function(num) return '[[Smissmas ' .. num .. ' Festive Gift' .. if_lang .. '|' .. item_name('smissmas ' .. num .. ' festive gift') .. ']]' end,
+
  ['xmas'] = function(num) return '[[Smissmas ' .. num .. ' Festive Gift' .. if_lang .. '|' .. item_name('smissmas ' .. num .. ' festive gift') .. ']]' end,
                ['winter'] = function(num) return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Unlocked Winter ' .. num .. ' Cosmetic Case|' .. item_name('unlocked winter ' .. num .. ' cosmetic case') .. ']]' end,
+
  ['winter'] = function(num) return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Unlocked Winter ' .. num .. ' Cosmetic Case|' .. item_name('unlocked winter ' .. num .. ' cosmetic case') .. ']]' end,
                ['winter-strange'] = function(num) return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Unlocked Winter ' .. num .. ' Cosmetic Case|' .. item_name('unlocked winter ' .. num .. ' cosmetic case') .. ']]' .. paren('[[Unique' .. if_lang .. '|' .. item_name('unique') .. ']] ' .. common_string('and') .. ' [[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
+
  ['winter-strange'] = function(num) return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Unlocked Winter ' .. num .. ' Cosmetic Case|' .. item_name('unlocked winter ' .. num .. ' cosmetic case') .. ']]' .. paren('[[Unique' .. if_lang .. '|' .. item_name('unique') .. ']] ' .. common_string('and') .. ' [[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
['crate'] = function(num) return '[[' .. status(num) .. if_lang .. '#' .. num .. '|' .. common_string('uncrate') .. ' #' .. num .. ']]' end,
+
  ['crate'] = function(num) return '[[' .. status(num) .. if_lang .. '#' .. num .. '|' .. common_string('uncrate') .. ' #' .. num .. ']]' end,
['crate-strange'] = function(num) return '[[' .. status(num) .. if_lang .. '#' .. num .. '|' .. common_string('uncrate') .. ' #' .. num .. ']]' .. paren('[[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
+
  ['crate-strange'] = function(num) return '[[' .. status(num) .. if_lang .. '#' .. num .. '|' .. common_string('uncrate') .. ' #' .. num .. ']]' .. paren('[[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
['crate-festive'] = function(num) return '[[' .. status(num) .. if_lang .. '#' .. num .. '|' .. common_string('uncrate') .. ' #' .. num .. ']]' .. paren('[[Festive weapons' .. if_lang .. '|' .. item_name('festive') .. ']]') end,
+
  ['crate-festive'] = function(num) return '[[' .. status(num) .. if_lang .. '#' .. num .. '|' .. common_string('uncrate') .. ' #' .. num .. ']]' .. paren('[[Festive weapons' .. if_lang .. '|' .. item_name('festive') .. ']]') end,
['crate-haunted'] = function(num) return '[[' .. status(num) .. if_lang .. '#' .. num .. '|' .. common_string('uncrate') .. ' #' .. num .. ']]' .. paren('[[Haunted' .. if_lang .. '|' .. item_name('haunted') .. ']]') end,
+
  ['crate-haunted'] = function(num) return '[[' .. status(num) .. if_lang .. '#' .. num .. '|' .. common_string('uncrate') .. ' #' .. num .. ']]' .. paren('[[Haunted' .. if_lang .. '|' .. item_name('haunted') .. ']]') end,
['strangifier-crate-'] = function(num) return '[[Strangifier' .. if_lang .. '|' .. item_name('strangifier') .. ']]<sup>' .. tooltip('?', common_string('uncrateable from series number crate', num)) .. '</sup>' .. paren('[[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
+
  ['strangifier-crate-'] = function(num) return '[[Strangifier' .. if_lang .. '|' .. item_name('strangifier') .. ']]<sup>' .. tooltip('?', common_string('uncrateable from series number crate', num)) .. '</sup>' .. paren('[[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
['strangifier-series-'] = function(num) return '[[Strangifier' .. if_lang .. '|' .. item_name('strangifier') .. ']]<sup>' .. tooltip('?', common_string('series number chemistry sets', num)) .. '</sup>' end,
+
  ['strangifier-series-'] = function(num) return '[[Strangifier' .. if_lang .. '|' .. item_name('strangifier') .. ']]<sup>' .. tooltip('?', common_string('series number chemistry sets', num)) .. '</sup>' end,
['unusual-'] = function(num) return '[[Mann Co. Supply Crate' .. if_lang .. '|' .. common_string('uncrate') .. ']]' .. paren('[[Unusual' .. if_lang .. '#Group ' .. num .. '|' .. item_name('unusual') .. ']]') end,
+
  ['unusual-'] = function(num) return '[[Mann Co. Supply Crate' .. if_lang .. '|' .. common_string('uncrate') .. ']]' .. paren('[[Unusual' .. if_lang .. '#Group ' .. num .. '|' .. item_name('unusual') .. ']]') end,
 
 
 
}
 
}
  
 
-- Some strings that were present in Dictionary/availcore and thus might be used somewhere.
 
-- Some strings that were present in Dictionary/availcore and thus might be used somewhere.
 
local backwards_compat = {
 
local backwards_compat = {
['store'] = 'purchase',
+
  ['store'] = 'purchase',
['achievement'] = 'unlock',
+
  ['achievement'] = 'unlock',
['strangifier-strange'] = 'strangifier',
+
  ['strangifier-strange'] = 'strangifier',
['strangifier'] = 'strangifier', -- Deprecated
+
  ['strangifier'] = 'strangifier', -- String deprecated, this adds it to the tracking category
  
['crate-naughty'] = 'crate35-festive',
+
  ['crate-naughty'] = 'crate35-festive',
['crate-naughty2012'] = 'crate52-festive',
+
  ['crate-naughty2012'] = 'crate52-festive',
['crate-naughty2013'] = 'crate78-festive',
+
  ['crate-naughty2013'] = 'crate78-festive',
['crate-naughty2014'] = 'crate88-festive',
+
  ['crate-naughty2014'] = 'crate88-festive',
['crate-nice'] = 'crate36',
+
  ['crate-nice'] = 'crate36',
['crate-nice2012'] = 'crate53',
+
  ['crate-nice2012'] = 'crate53',
['crate-nice2013'] = 'crate79',
+
  ['crate-nice2013'] = 'crate79',
['crate-nice2014'] = 'crate89',
+
  ['crate-nice2014'] = 'crate89',
['crate-nohaunt'] = 'crate',
+
  ['crate-nohaunt'] = 'crate',
['strongbox'] = 'crate81'
+
  ['strongbox'] = 'crate81',
 +
  ['winter2016'] = 'crate105'
 
}
 
}
  
 
function p.avail(f)
 
function p.avail(f)
-- Precompute the page's language.
+
  -- Precompute the page's language.
frame = f
+
  frame = f
local args = f:getParent().args
+
  local args = f:getParent().args
count = 0
+
  count = 0
for _ in pairs(args) do count = count + 1 end
+
  for _ in pairs(args) do count = count + 1 end
if count == 0 then -- There is no other way to count table length in lua.
+
  if count == 0 then -- There is no other way to count table length in lua.
args = f.args
+
    args = f.args
end
+
  end
if_lang = frame:expandTemplate{title='If lang'}
+
  if_lang = frame:expandTemplate{title='If lang'}
  
-- Avail is called with a long list of arguments. Each one needs to be translated and comma-separated.
+
  -- Avail is called with a long list of arguments. Each one needs to be translated and comma-separated.
avail_string = ''
+
  avail_string = ''
for i, arg in ipairs(args) do
+
  for i, arg in ipairs(args) do
arg = mw.ustring.lower(arg)
+
    arg = mw.ustring.lower(arg)
-- Backwards compatibility
+
    -- Backwards compatibility
if backwards_compat[arg] ~= nil then
+
    if backwards_compat[arg] ~= nil then
avail_string = avail_string .. '[[Category:Outdated Availability Parameters]]'
+
      avail_string = avail_string .. '[[Category:Outdated Availability Parameters]]'
arg = backwards_compat[arg]
+
      arg = backwards_compat[arg]
end
+
    end
  
-- Crate 46 is a Scorched Crate, which is a string that isn't used anywhere else.
+
    -- Crate 46 is a Scorched Crate, which is a string that isn't used anywhere else.
if arg == 'crate46' then arg = 'crate-scorched' end
+
    if arg == 'crate46' then arg = 'crate-scorched' end
-- Enchantment: Eternawen was uncratable from #74, and cannot be Haunted.
+
    -- Enchantment: Eternaween was uncratable from #74, and cannot be Haunted.
if arg == 'crate74' then arg = 'crate74-haunted' end
+
    if arg == 'crate74' then arg = 'crate74-haunted' end
  
-- Matches strings like 'craft' 'crate1' 'crate26-strange'
+
    -- Matches strings like 'craft' 'crate1' 'crate26-strange'
-- Strings like 'crate26-strange' become 'crate-strange' and '26'.
+
    -- Strings like 'crate26-strange' become 'crate-strange' and '26'.
name1, num, name2 = string.match(arg, '(%D*)(%d*)(%D*)')
+
    name1, num, name2 = string.match(arg, '(%D*)(%d*)(%D*)')
name = name1 .. name2
+
    name = name1 .. name2
  
if (args[i+2] ~= nil)
+
    if (args[i+2] ~= nil)
or (args[i+1] ~= nil and args['availability'] ~= nil)
+
    or (args[i+1] ~= nil and args['availability'] ~= nil)
then -- There are at least two arguments left in the list
+
      then -- There are at least two arguments left in the list
if if_lang == '/zh-hans' then
+
      if if_lang == '/zh-hans' then
avail_string = avail_string .. lookup[name](num) .. '、'
+
        avail_string = avail_string .. lookup[name](num) .. '、'
elseif if_lang == '/zh-hant' then
+
      elseif if_lang == '/zh-hant' then
avail_string = avail_string .. lookup[name](num) .. ','
+
        avail_string = avail_string .. lookup[name](num) .. ','
else
+
      else
avail_string = avail_string .. lookup[name](num) .. ', '
+
        avail_string = avail_string .. lookup[name](num) .. ', '
end
+
      end
elseif (args[i+1] ~= nil and args['availability'] == nil)
+
    elseif (args[i+1] ~= nil and args['availability'] == nil)
or (args[i+1] == nil and args['availability'] ~= nil)
+
    or (args[i+1] == nil and args['availability'] ~= nil)
then -- There is exactly one more argument in the list
+
      then -- There is exactly one more argument in the list
avail_string = avail_string .. lookup[name](num) .. ' ' .. common_string('or') .. ' '
+
      avail_string = avail_string .. lookup[name](num) .. ' ' .. common_string('or') .. ' '
else -- args[i+1] == nil and args['availability] == nil
+
    else -- args[i+1] == nil and args['availability] == nil
avail_string = avail_string .. lookup[name](num)
+
      avail_string = avail_string .. lookup[name](num)
end
+
    end
end -- End looping through arguments.
+
  end -- End looping through arguments.
if args['availability'] ~= nil then
+
  if args['availability'] ~= nil then
avail_string = avail_string .. args['availability']
+
    avail_string = avail_string .. args['availability']
end
+
  end
  
return avail_string
+
  return avail_string
 
end
 
end
  
 
return p
 
return p

Revision as of 20:50, 7 January 2018

Module:Availability (aka Template:Availability) is used to display and autotranslate the 'Availability' section in {{Item infobox}}. Preferably, the shortcut {{avail}} should be used.

For future reference, if creating new additions, the key cannot include a number, or it will be parsed out. Thus, if you want to add a string like xmas2015, instead add it to the Multipart strings with xmas and use num to represent the 2015.


Entries

Parameter Output
audition-reel Audition Reel
bread-box Bread Box (Unique and Strange)
chemistryset Chemistry Set
case-any Uncrate (any case)
case-bonus Uncrate (bonus)
collectors Chemistry Set (Collector's)
contract Contract (Decorated)
contract-unique ConTracker
craft Craft
craft-expired Craft (expired)
creepy-crate Unlocked Creepy Crate
directors Director's Cut Reel
distributed Distributed
distributed-duels Distributed (periodical)
distributed-expired Distributed (expired)
distributed-gifts Distributed (periodical)
distributed-stamps Distributed (periodical)
drop Drop
drop-expired Drop (expired)
festive-gift Smissmas 2015 Festive Gift
gift-cauldron Halloween Gift Cauldron
goodie-cauldron Antique Halloween Goodie Cauldron (limited)
halloween-package Halloween Package
halloween-purchase Purchase
halloween-purchase-expired Purchase (expired)
hauntedgift Haunted Halloween Gift (expired)
jungleinferno-campaign Jungle Inferno Campaign Pass (limited)
jungleinferno-contracts Jungle Inferno Contracts Pass
keyless-crate Unlocked Cosmetic Crate (Unique and Strange)
keyless-crate-unusual Unlocked Cosmetic Crate (Unique, Strange and Unusual)
mvm As Mann vs. Machine reward
pallet-of-crates Pallet of Crates
pile-of-curses Pile of Curses (expired)
promotional Promotional
promotional-craft Promotional (craft)
promotional-expired Promotional (expired)
promotional-expired-codes Promotional (expired)
promotional-unlock Promotional (unlock)
purchase Purchase
purchase-limited Purchase (limited)
retired Retired
stock Stock
stockpile Stockpile Crate
trade-up Trade-Up
transmute Halloween Transmute (Untradable)
unavailable Unavailable
unlock Unlock
unusual Uncrate (Unusual)
unusual-expired Uncrate (Unusual) (expired)
warpaint War Paint (Decorated)
MvM related strings
mannup Reward
australium Reward (Australium)
botkiller Reward (Botkiller)
mvm-both-types Reward (Botkiller and Australium)
Dynamic strings (mostly used for crate numbers). The numeric value is automatically parsed.
crate1 Uncrate #1
crate2-strange Uncrate #2 (Strange)
crate3-festive Uncrate #3 (Festive)
crate4-haunted Uncrate #4 (Haunted) (expired)
crate5-bonus Uncrate #5 (bonus)
crate6-expired Uncrate #6 (expired)
crate91 Uncrate #91
crate92 Uncrate #92
case104 Uncrate #104 (Creepy Crawly Case)
case105 Uncrate #105 (Unlocked Winter 2016 Cosmetic Case)

Usage

Backwards compatibility

{{Availability}} changes over time, and thus has some parameters which have been deprecated. They will still function in this template, but their use will place the page into Outdated Availability Parameters. Please replace them with the appropriate new value.

Outdated Parameter New Parameter Output
crate-scorched crate46 Uncrate #46
crate74 crate74-haunted Uncrate #74 (Haunted) (expired)
crate74-expired crate74-haunted Uncrate #74 (Haunted) (expired)
xmas2015 festive-gift Smissmas 2015 Festive Gift
winter2016 case105 Uncrate #105 (Unlocked Winter 2016 Cosmetic Case)
winter2016-strange case105 Uncrate #105 (Unlocked Winter 2016 Cosmetic Case)
winter2016-unusual case105 Uncrate #105 (Unlocked Winter 2016 Cosmetic Case)
unusual-# unusual Uncrate (Unusual)

local p = {}

-- Imports the function status(number), which returns whether or not a crate is Active or Retired. This is in a separate file so that it can be updated *without* staff intervention.
require('Module:Availability/crate')

-- Defined here so that it can be referenced inside the next three functions
local frame = nil

-- Expands the template Tooltip for a given pair of values.
function tooltip(tool, tip)
  return frame:expandTemplate{title='Tooltip', args={tool, tip}}
end

-- Expands the template Item name for a given value.
function item_name(arg)
  return frame:expandTemplate{title='Item name', args={arg}}
end

-- Expands the template Common string for a given value. Note that some common string values include an additional parameter, here called opt_arg.
function common_string(arg, opt_arg)
  return frame:expandTemplate{title='Common string', args={arg, opt_arg}}
end

-- Returns ' (text)', with correct parenthesis characters in Chinese.
function paren(text)
  if if_lang == '/zh_hans' or if_lang == '/zh-hant' then
    return ' (' .. text .. ')'
  else
    return ' (' .. text .. ')'
  end
end

-- Replaces the old Dictionary/templatecore strings
lookup = {
  -- Singleton strings (without a number)
  ['audition-reel'] = function() return '[[Mann Co. Supply Crate/Seriesless_crates' .. if_lang .. '#Audition Reel|' .. common_string('audition reel') .. ']]' end,
  ['australium'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' .. paren('[[Australium weapons' .. if_lang .. '|' .. common_string('australium') .. ']]') end,
  ['botkiller'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' .. paren('[[Botkiller weapons' .. if_lang .. '|' .. common_string('botkiller') .. ']]') end,
  ['bread-box'] = function() return '[[Bread Box' .. if_lang .. '|' .. item_name('bread box') .. ']]' .. paren('[[Unique' .. if_lang .. '|' .. item_name('unique') .. ']] ' .. common_string('and') .. ' [[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
  ['chemistryset'] = function() return '[[Chemistry Set' .. if_lang .. '|' .. item_name('chemistry set') .. ']]' end,
  ['collectors'] = function() return '[[Chemistry Set' .. if_lang .. '|' .. item_name('chemistry set') .. ']]' .. paren('[[Collectors' .. if_lang .. '|' .. item_name('collector\'s') .. ']]') end,
  ['contract'] = function() return '[[Gun Mettle Campaign' .. if_lang .. '#Contracts|' .. common_string('contract') .. ']]' .. paren('[[Decorated' .. if_lang .. '|' .. item_name('decorated') .. ']]') end,
  ['contract-unique'] = function() return '[[ConTracker' .. if_lang .. '|' .. common_string('contracker') .. ']]' .. paren('[[Unique' .. if_lang .. '|' .. item_name('unique') .. ']]') end,
  ['craft'] = function() return '[[Crafting' .. if_lang .. '|' .. common_string('craft') .. ']]' end,
  ['crate-scorched'] = function() return '[[Mann Co. Supply Crate/Retired series' .. if_lang .. '#46|' .. common_string('uncrate') .. ' #46]]' .. paren(common_string('scorched')) end,
  ['creepy-crate'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Unlocked Creepy Crates|' .. item_name('unlocked creepy crate') .. ']]' end,
  ['directors'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Director\'s Cut|' .. common_string('director\'s cut') .. ']]' end,
  ['distributed'] = function() return common_string('distributed') end,
  ['drop'] = function() return '[[Item drop system' .. if_lang .. '|' .. common_string('drop') .. ']]' end,
  ['gift-cauldron'] = function() return '[[Halloween Gift Cauldron' .. if_lang .. '|' .. item_name('halloween gift cauldron') .. ']]' end,
  ['halloween-purchase'] = function() return '[[Mann Co. Store' .. if_lang .. '|' .. tooltip(common_string('purchase'), common_string('purchase-halloween')) .. ']]' end,
  ['hauntedgift'] = function() return '[[Haunted Halloween Gift' .. if_lang .. '|' .. item_name('haunted halloween gift') .. ']]' end,
  ['keyless-crate'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Unlocked Cosmetic Crates|' .. item_name('unlocked cosmetic crate') .. ']]' .. paren('[[Unique' .. if_lang .. '|' .. item_name('unique') .. ']] ' .. common_string('and') .. ' [[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
  ['mannup'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' end,
  ['mvm-both-types'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' .. paren('[[Botkiller weapons' .. if_lang .. '|' .. common_string('botkiller') .. ']] ' .. common_string('and') .. ' [[Australium weapons' .. if_lang .. '|' .. common_string('australium') .. ']]') end,
  ['mvm'] = function() return '[[Mann vs. Machine' .. if_lang .. '|' .. common_string('mvm reward') .. ']]' end,
  ['promotional'] = function() return '[[Promotional items' .. if_lang .. '|' .. common_string('promotional') .. ']]' end,
  ['purchase'] = function() return '[[Mann Co. Store' .. if_lang .. '|' .. common_string('purchase') .. ']]' end,
  ['retired'] = function() return common_string('retired') end,
  ['stock'] = function() return '[[Stock weapons' .. if_lang .. '|' .. mw.getContentLanguage():ucfirst(item_name('stock')) .. ']]' end,
  ['stockpile'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Stockpile|' .. common_string('stockpile crate') .. ']]' end,
  ['strangifier'] = function() return '[[Strangifier' .. if_lang .. '|' .. item_name('strangifier') .. ']]'.. paren('[[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
  ['trade-up'] = function() return '[[Trade-Up' .. if_lang .. '|' .. common_string('trade-up') .. ']]' end,
  ['transmute'] = function() return '[[Halloween Transmute' .. if_lang .. '|' .. common_string('halloween transmute') .. ']] ' .. paren('[[Trading' .. if_lang .. '|' .. common_string('Untradable') .. ']]') end,
  ['unavailable'] = function() return common_string('unavailable') end,
  ['unlock'] = function() return '[[Achievement items' .. if_lang .. '|' .. common_string('unlock') .. ']]' end,
  ['unusual'] = function() return '[[Mann Co. Supply Crate' .. if_lang .. '|' .. common_string('uncrate') .. ']]' .. paren('[[Unusual' .. if_lang .. '|' .. item_name('unusual') .. ']]') end,
    -- Multipart strings (with a number)
  ['xmas'] = function(num) return '[[Smissmas ' .. num .. ' Festive Gift' .. if_lang .. '|' .. item_name('smissmas ' .. num .. ' festive gift') .. ']]' end,
  ['winter'] = function(num) return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Unlocked Winter ' .. num .. ' Cosmetic Case|' .. item_name('unlocked winter ' .. num .. ' cosmetic case') .. ']]' end,
  ['winter-strange'] = function(num) return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Unlocked Winter ' .. num .. ' Cosmetic Case|' .. item_name('unlocked winter ' .. num .. ' cosmetic case') .. ']]' .. paren('[[Unique' .. if_lang .. '|' .. item_name('unique') .. ']] ' .. common_string('and') .. ' [[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
  ['crate'] = function(num) return '[[' .. status(num) .. if_lang .. '#' .. num .. '|' .. common_string('uncrate') .. ' #' .. num .. ']]' end,
  ['crate-strange'] = function(num) return '[[' .. status(num) .. if_lang .. '#' .. num .. '|' .. common_string('uncrate') .. ' #' .. num .. ']]' .. paren('[[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
  ['crate-festive'] = function(num) return '[[' .. status(num) .. if_lang .. '#' .. num .. '|' .. common_string('uncrate') .. ' #' .. num .. ']]' .. paren('[[Festive weapons' .. if_lang .. '|' .. item_name('festive') .. ']]') end,
  ['crate-haunted'] = function(num) return '[[' .. status(num) .. if_lang .. '#' .. num .. '|' .. common_string('uncrate') .. ' #' .. num .. ']]' .. paren('[[Haunted' .. if_lang .. '|' .. item_name('haunted') .. ']]') end,
  ['strangifier-crate-'] = function(num) return '[[Strangifier' .. if_lang .. '|' .. item_name('strangifier') .. ']]<sup>' .. tooltip('?', common_string('uncrateable from series number crate', num)) .. '</sup>' .. paren('[[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
  ['strangifier-series-'] = function(num) return '[[Strangifier' .. if_lang .. '|' .. item_name('strangifier') .. ']]<sup>' .. tooltip('?', common_string('series number chemistry sets', num)) .. '</sup>' end,
  ['unusual-'] = function(num) return '[[Mann Co. Supply Crate' .. if_lang .. '|' .. common_string('uncrate') .. ']]' .. paren('[[Unusual' .. if_lang .. '#Group ' .. num .. '|' .. item_name('unusual') .. ']]') end,
}

-- Some strings that were present in Dictionary/availcore and thus might be used somewhere.
local backwards_compat = {
  ['store'] = 'purchase',
  ['achievement'] = 'unlock',
  ['strangifier-strange'] = 'strangifier',
  ['strangifier'] = 'strangifier', -- String deprecated, this adds it to the tracking category

  ['crate-naughty'] = 'crate35-festive',
  ['crate-naughty2012'] = 'crate52-festive',
  ['crate-naughty2013'] = 'crate78-festive',
  ['crate-naughty2014'] = 'crate88-festive',
  ['crate-nice'] = 'crate36',
  ['crate-nice2012'] = 'crate53',
  ['crate-nice2013'] = 'crate79',
  ['crate-nice2014'] = 'crate89',
  ['crate-nohaunt'] = 'crate',
  ['strongbox'] = 'crate81',
  ['winter2016'] = 'crate105'
}

function p.avail(f)
  -- Precompute the page's language.
  frame = f
  local args = f:getParent().args
  count = 0
  for _ in pairs(args) do count = count + 1 end
  if count == 0 then -- There is no other way to count table length in lua.
    args = f.args
  end
  if_lang = frame:expandTemplate{title='If lang'}

  -- Avail is called with a long list of arguments. Each one needs to be translated and comma-separated.
  avail_string = ''
  for i, arg in ipairs(args) do
    arg = mw.ustring.lower(arg)
    -- Backwards compatibility
    if backwards_compat[arg] ~= nil then
      avail_string = avail_string .. '[[Category:Outdated Availability Parameters]]'
      arg = backwards_compat[arg]
    end

    -- Crate 46 is a Scorched Crate, which is a string that isn't used anywhere else.
    if arg == 'crate46' then arg = 'crate-scorched' end
    -- Enchantment: Eternaween was uncratable from #74, and cannot be Haunted.
    if arg == 'crate74' then arg = 'crate74-haunted' end

    -- Matches strings like 'craft' 'crate1' 'crate26-strange'
    -- Strings like 'crate26-strange' become 'crate-strange' and '26'.
    name1, num, name2 = string.match(arg, '(%D*)(%d*)(%D*)')
    name = name1 .. name2

    if (args[i+2] ~= nil)
    or (args[i+1] ~= nil and args['availability'] ~= nil)
      then -- There are at least two arguments left in the list
      if if_lang == '/zh-hans' then
        avail_string = avail_string .. lookup[name](num) .. '、'
      elseif if_lang == '/zh-hant' then
        avail_string = avail_string .. lookup[name](num) .. ','
      else
        avail_string = avail_string .. lookup[name](num) .. ', '
      end
    elseif (args[i+1] ~= nil and args['availability'] == nil)
    or (args[i+1] == nil and args['availability'] ~= nil)
      then -- There is exactly one more argument in the list
      avail_string = avail_string .. lookup[name](num) .. ' ' .. common_string('or') .. ' '
    else -- args[i+1] == nil and args['availability] == nil
      avail_string = avail_string .. lookup[name](num)
    end
  end -- End looping through arguments.
  if args['availability'] ~= nil then
    avail_string = avail_string .. args['availability']
  end

  return avail_string
end

return p