Module:ItemData: Difference between revisions

add comma formatting
tidy, replace commas with language
Line 2: Line 2:
local data = mw.loadJsonData("Data:ItemData.json")
local data = mw.loadJsonData("Data:ItemData.json")


-- returns the value of a specific item
-- returns the table of a specific item
function get_json_item(name)
function get_json_item(name)
for i,v in pairs(data) do
for _, v in pairs(data) do
if (v["Name"] == name) then
if (v["Name"] == name) then
return v
return v
Line 13: Line 13:


-- Adds commas delimiter to the thousands place
-- Adds commas delimiter to the thousands place
-- NOTE: Thousands delimiters are language specific. Some languages use commas, periods, or spaces.
local lang = mw.language.getContentLanguage()
-- TODO: Implement language check either through extension or lua
local function Format(amount)
function Format(amount)
     local formatted = amount
     local formatted = amount
     while true do
     return lang:formatNum(tonumber(formatted))
        formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
        if (k == 0) then
            break
        end
    end
    return formatted
end
end