ARK: Survival Evolved Wiki
ARK: Survival Evolved Wiki

Updating the data:

  • Moduł:Dv/data should be kept synchronized with its English version as the translations are kept in a separate module.
  • Moduł:Dv takes care of booleans (values like "yes" and "no"). Text values are translated in a separate module, Moduł:Dv/pl-diff.
  • Someone will eventually update pl-diff (AKA our changes) to reflect the changes.

Zastrzeżenia co do aktualizacji modułu:

  • Moduł:Dv/data powinien być dokładnie taki sam jak angielski odpowiednik.
  • Moduł:Dv przekształci wszelkie wartości typu "yes" i "no" na nasze "tak" i "nie".
  • Spolszczenie wartości tekstowych znajduje się w Moduł:Dv/pl-diff. Pamiętaj, że moduł ten odnosi się do angielskich nazw, a nie do polskich - wg. niego nie ma tytanozaura, jest za to titanosaur.
  • Przekształcenia nazw angielskich na polskie dodawaj w Moduł:Dv/pl-names.

----------------------------------------------------------------------------------------------------
-- Usage: use the Template:Dv
----------------------------------------------------------------------------------------------------

-- normalize accents
-- __Never__ assume that only lowercase cases are possible.
local function normalizeString(str)
    local accents = {}
        accents["ą"] = "a"
        accents["ć"] = "c"
        accents["ę"] = "e"
        accents["Ł"] = "l"
        accents["ł"] = "l"
        accents["ś"] = "s"
        accents["ó"] = "o"
        accents["Ż"] = "z"
        accents["ż"] = "z"
        accents["Ź"] = "z"
        accents["ź"] = "z"
    local newString = ''

    for char in string.gmatch(str, "([%z\1-\127\194-\244][\128-\191]*)") do
        if accents[char] ~= nil then
            newString = newString..accents[char]
        else
            newString = newString..char
        end
    end

    return newString
end

-- override values in table dst with values of table src, or adds them
local function merge(dst, src)
  for k, v in pairs(src) do
    if type(dst[k]) == 'table' and type(v) == 'table' then
      dst[k] = merge(dst[k], v)
    else
      dst[k] = v
    end
  end
  return dst
end

local function deepcopy(orig)
  if type(orig) == 'table' then
    local copy = {}
    for k, v in pairs(orig) do
      copy[deepcopy(k)] = deepcopy(v)
    end
    return copy
  end
  return orig
end

local function createVardefines(t, f, prefix)
  for k, v in pairs(t) do
    if type(v) == 'table' then
      f:callParserFunction('#vardefine:' .. (prefix == '' and prefix or prefix .. '/') .. k, 'table')
      createVardefines(v, f, (prefix == '' and prefix or prefix .. '/') .. k)
    else
      -- translate "Yes" and "No" to Polish
      if v == 'Yes' then
        v = 'Tak'
      end
      if v == 'No' then
        v = 'Nie'
      end

      f:callParserFunction('#vardefine:' .. (prefix == '' and prefix or prefix .. '/') .. k, v)
    end
  end  
end

-- Automatically translate to avoid duplicating in pl-diff
local function convertBools(t)
  for k, v in pairs(t) do
    if type(t[k]) == 'table' then
      t[k] = convertBools(t[k])
    else
      if v == "Unreleased" then
        t[k] = "Niewydane"
      end

      if v == "Released" then
        t[k] = "Wydane"
      end

      if v == "Yes" then
        t[k] = "Tak"
      end

      if v == "No" then
        t[k] = "Nie"
      end

      if v == "None" then
        t[k] = "Nic"
      end
    end
  end

  return t
end

local p = {}
function p.data(f)
  local args = f:getParent().args
  -- expects one or more non-named arguments in the template, the /-separated path to the data
  if args[1] == nil then
    return 'arguments expected, see documentation of Template:Dv'
  end
  -- concat all non-named arguments (args is not a real table, deepcopy creates one)
  local path = table.concat(deepcopy(args), '/')

  -- replace all accented characters
  -- assume that we are sure there is not going to be a name beginning with an accent
  path = normalizeString(path)

  -- remove non-word characters except / then lowercase
  path = path:gsub('[^%w/]', ''):lower()

  local folders = {} -- list of path parts
  for part in path:gmatch("[^/]+") do
    table.insert(folders, part)
  end

  -- separate creature name from the rest of the path
  local creature = table.remove(folders, 1)

  -- from PL diff: replace creature localised name with actual name (or an alias)
  local polishNames = mw.loadData('Module:dv/pl-names')
  if polishNames[creature] ~= nil then
    creature = polishNames[creature]
  end

  -- replace creature name alias with actual name
  local aliases = mw.loadData('Module:dv/aliases')
  if aliases[creature] ~= nil then
    creature = aliases[creature]
  end

  -- retrieve the database
  local data = mw.loadData('Module:dv/data')

  -- search the creature
  local node = data[creature]
  if node == nil then
    return '' -- 'creature data not found: ' .. creature
  end

  -- from PL diff: load overrides
  local pldiffdata = mw.loadData('Module:dv/pl-diff')

  -- merge inherited data with own data
  if node.inherits ~= nil and data[node.inherits] ~= nil then
    -- from PL diff: merge inherited data with own data (BEFORE ENGLISH INHERITANCE)
    if pldiffdata[node.inherits] ~= nil then
      node = merge(deepcopy(pldiffdata[node.inherits]), node)
    end

    node = merge(deepcopy(data[node.inherits]), node)
  end

  -- apply overrides from other section of 'data'
  if type(node.overridewith) == 'string' and data[node.overridewith] ~= nil then
    node = merge(node, data[node.overridewith])

    -- from PL diff: merge inherited data with own data (BEFORE ENGLISH INHERITANCE)
    if pldiffdata[node.overridewith] ~= nil then
      node = merge(node, pldiffdata[node.overridewith])
    end
  end

  -- from PL diff: search creature
  local diffnode = pldiffdata[creature]
  if diffnode ~= nil then
    -- from PL diff: apply overrides
    node = merge(deepcopy(node), diffnode)
  end

  -- PL: Translate "yes" and "no"
  --node = convertBools(deepcopy(node))

  -- search data for path
  for _,f in ipairs(folders) do
    if node[f] ~= nil then
      node = node[f]
    else
      return '' -- no data available for given path
    end
  end

  if type(node) == 'table' then
    if args.defineVars ~= nil then
      createVardefines(node, f, args.defineVars)
      return 'variables defined'
    end
    return 'path not specific enough: ' .. path -- given path leads to a folder instead of a value
  end
  return node
end
return p