Warframe Wiki
Nie podano opisu zmian
Nie podano opisu zmian
Linia 137: Linia 137:
 
end
 
end
 
module_export.proc_to_polish = proc_to_polish
 
module_export.proc_to_polish = proc_to_polish
 
local function integer_ends_with(number, val)
 
local str = tostring(number)
 
if type(val) == "table" then
 
return contains(table_each(val, tostring), str:sub(-1))
 
else
 
return tostring(val) == str:sub(-1)
 
end
 
end
 
module_export.new = integer_ends_with
 
   
 
-- Add handling of words ending with -ek
 
-- Add handling of words ending with -ek
Linia 156: Linia 146:
 
local last_letters = word:sub(-3)
 
local last_letters = word:sub(-3)
 
if count == 1 then return word
 
if count == 1 then return word
  +
-- must be an integer
elseif is_integer(count) and integer_ends_with(count, {1, 2, 3, 4}) then
 
  +
-- must end with 1, 2, 3, 4 and must not end with 11, 12, 13, ..., 18, 19
 
elseif is_integer(count) and
  +
(contains({ 1, 2, 3, 4 }, count) or
  +
(count > 10 and
  +
not contains({ "11", "12", "13", "14", "15", "16", "17", "18", "19" }, tostring(count):sub(-2)) and
  +
contains({ "1", "2", "3", "4" }, tostring(count):sub(-1))
  +
)
  +
)
 
then
 
if last_letters[3] == "a" then
 
if last_letters[3] == "a" then
 
word = word:sub(1, -1)
 
word = word:sub(1, -1)

Wersja z 12:15, 11 sie 2018

Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Utils/opis

local module_export = {}

local function is_integer(number)
    return number == math.floor(number)
end
module_export.is_integer = is_integer

local function sum(...)
    local sum = 0;
    for i = 1, arg.n do
        sum = sum + arg[i]
    end
    return sum
end
module_export.sum = sum

-- Calculates the size of an array
local function array_size(arr)
    arr = arr or {}
    local size = 0
    for _ in ipairs(arr) do
        size = size + 1
    end
    return size
end
module_export.array_size = array_size

-- Generalized unpack. Upnacks both array and dictionary part of a table
local function unpack_any_table(t)
    t = t or {} -- nil will throw
    
    local indexed_table = {}
    for k, v in pairs(t) do
        table.insert(indexed_table, v)
    end
    return unpack(indexed_table) 
end
module_export.unpack_any_table = unpack_any_table

-- Returns keys of a table (array and dictionary)
local function table_keys(t)
    local keys = {}
    for k, v in pairs(t) do
        table.insert(keys, k)
    end
    return keys
end
module_export.table_keys = table_keys

-- table.concat (doesn't work for some reason) substitue
-- Concatenates indexed values from t using sep
-- sep defaults to empty string
local function table_concat(t, sep)
    sep = sep or ''
    local result = ''
    for i, v in ipairs(t) do
        if(i ~= 1) then
            result = result .. sep     
        end
        result = result .. v
    end
    return result
end
module_export.table_concat = table_concat

local function table_each(t, callback)
    local indexed_table = {}
    for k, v in pairs(t) do
        table.insert(indexed_table, callback(v, k))
    end
    return indexed_table
end
module_export.table_each = table_each

local function contains(t, val)
    for i, v in ipairs(t) do
        if v == val then return true end
    end
    
    return false
end
module_export.contains = contains

local function to_precision(value, precision)
    return string.format("%." .. precision .. "f", value)
end
module_export.to_precision = to_precision

local function to_minimum_precision(value, min_precision)
    local multiplied_num = value * 10 ^ min_precision
    if math.floor(multiplied_num) ~= multiplied_num then
        return value
    else
        return string.format("%." .. min_precision .. "f", value)
    end
end
module_export.to_minimum_precision = to_minimum_precision

local function to_percent(value)
    return to_minimum_precision(value * 100, 1) .. "%"
end
module_export.to_percent = to_percent

local function proc_to_polish(proc)
    proc = proc:lower() -- make case insensitive
    
    if proc == "impact" then return "Miażdżące"
    elseif proc == "slash" then return "Tnące"
    elseif proc == "puncture" then return "Przebijające"
    elseif proc == "cold" then return "Zimno"
    elseif proc == "electricity" then return "Elektryczne"
    elseif proc == "heat" then return "Ogień"
    elseif proc == "toxin" then return "Toksyna"
    elseif proc == "blast" then return "Wybuch"
    elseif proc == "corrosive" then return "Żrące"
    elseif proc == "gas" then return "Gaz"
    elseif proc == "magnetic" then return "Magnetyczne"
    elseif proc == "radiation" then return "Radiacja"
    elseif proc == "viral" then return "Wirusowe"
    end
    
    if proc == "tnace" then return "Tnące"
    elseif proc == "miazdzace" then return "Miażdżące"
    elseif proc == "przebijajace" then return "Przebijające"
    elseif proc == "ogien" then return "Ogień"
    elseif proc == "zimno" then return "Zimno"
    elseif proc == "elektryczne" then return "Elektryczne"
    elseif proc == "toksyna" then return "Toksyna"
    elseif proc == "toksyczne" then return "Toksyczne" -- in case
    elseif proc == "wybuch" then return "Wybuch"
    elseif proc == "zrace" then return "Żrące"
    elseif proc == "gaz" then return "Gaz"
    elseif proc == "magnetyczne" then return "Magnetyczne"
    elseif proc == "radiacja" then return "Radiacja"
    elseif proc == "wirusowe" then return "Wirusowe"
    end
end
module_export.proc_to_polish = proc_to_polish

-- Add handling of words ending with -ek
local function make_polish_plural(word, count)
    local y_endings = { "b", "p", "d", "t", "f", "w", "ch", "ł", "m", "n", "r", "s", "z" }
    local i_endings = { "k", "g" }
    local e_endings = { "dzi", "dź", "ci", "ć", "j", "l", "ni", "ń", "si", "ś", "zi", "ź", "dz", "dż", "c", "cz", "rz", "ż", "sz" }
    
    local last_letters = word:sub(-3)
    if count == 1 then return word
    -- must be an integer
    -- must end with 1, 2, 3, 4 and must not end with 11, 12, 13, ..., 18, 19
    elseif is_integer(count) and 
           (contains({ 1, 2, 3, 4 }, count) or 
               (count > 10 and 
                not contains({ "11", "12", "13", "14", "15", "16", "17", "18", "19" }, tostring(count):sub(-2)) and 
                contains({ "1", "2", "3", "4" }, tostring(count):sub(-1))
               )
           ) 
    then
        if last_letters[3] == "a" then
            word = word:sub(1, -1)
            last_letters = word:sub(-3)
        end
        
        if contains(e_endings, last_letters) or contains(e_endings, last_letters:sub(2)) or contains(e_endings, last_letters:sub(3)) then
            return word .. "e"
        elseif contains(i_endings, last_letters:sub(3)) then
            return word .. "i"
        elseif contains(y_endings, last_letters:sub(2)) or contains(y_endings, last_letters:sub(3)) then
            return word .. "y"
        else
            return word .. "a"
        end
    else -- count not ending with 1-4 or count is a fractions
        -- Add more rules
        if word:sub(-2) == "ek" then
            return word:sub(1, -3) .. "ków"
        else 
            return word .. "ów"
        end
    end
end
module_export.make_polish_plural = make_polish_plural

return module_export