<commit_before>return function (loader)

  local Layer     = loader.require "layeredata"
  local Lustache  = loader.require "lustache"
  local Plural    = loader.require "i18n.plural"

  local I18n      = {}
  local Metatable = {}
  local Message   = {}

  setmetatable (I18n, Metatable)

  -- FIXME: remove
  function I18n.new (locale)
    return setmetatable ({
      _store  = {},
      _locale = locale,
    }, I18n)
  end

  function I18n.load (t)
    if type (t) ~= "table" then
      t = { t }
    end
    local depends = {}
    for _, name in ipairs (t) do
      local layer = Layer.new {
        name = name,
        data = loader.load (name .. ".i18n")
      }
      depends [#depends+1] = layer
    end
    local all = Layer.new { name = "i18n", data = {
        __refines__ = depends,
      }
    }
    local store = setmetatable ({}, {
      __index = function (_, key)
        local path = all [key]
        if path then
          local result = {}
          for k, p in Layer.pairs (path) do
            result [k] = p
          end
          return result
        end
      end,
    })
    return setmetatable ({
      _store  = store,
      _locale = false,
    }, I18n)
  end

  function I18n.__index (i18n, key)
    local entry = i18n._store [key]
    if not entry then
      error ("i18n key " .. tostring (key) .. " not found")
    end
    return setmetatable ({
      _key    = key,
      _entry  = entry,
      _locale = i18n._locale,
    }, Message)
  end

  function I18n.__call (i18n, data)
    if type (data) ~= "table" then
      return data
    end
    local function translate (locale, t)
      locale = t.locale or locale
      if type (t) ~= "table" then
        return t
      end
      for _, v in pairs (t) do
        if type (v) == "table" and not getmetatable (v) then
          translate (locale, v)<commit_msg>Add function to test if an i18n key is defined.<commit_after>return function (loader)

  local Layer     = loader.require "layeredata"
  local Lustache  = loader.require "lustache"
  local Plural    = loader.require "i18n.plural"

  local I18n      = {}
  local Metatable = {}
  local Message   = {}

  setmetatable (I18n, Metatable)

  -- FIXME: remove
  function I18n.new (locale)
    return setmetatable ({
      _store  = {},
      _locale = locale,
    }, I18n)
  end

  function I18n.load (t)
    if type (t) ~= "table" then
      t = { t }
    end
    local depends = {}
    for _, name in ipairs (t) do
      local layer = Layer.new {
        name = name,
        data = loader.load (name .. ".i18n")
      }
      depends [#depends+1] = layer
    end
    local all = Layer.new { name = "i18n", data = {
        __refines__ = depends,
      }
    }
    local store = setmetatable ({}, {
      __index = function (_, key)
        local path = all [key]
        if path then
          local result = {}
          for k, p in Layer.pairs (path) do
            result [k] = p
          end
          return result
        end
      end,
    })
    return setmetatable ({
      _store  = store,
      _locale = false,
    }, I18n)
  end

  function I18n.defines (i18n, key)
    return i18n._store [key]
  end

  function I18n.__index (i18n, key)
    local entry = i18n._store [key]
    if not entry then
      error ("i18n key " .. tostring (key) .. " not found")
    end
    return setmetatable ({
      _key    = key,
      _entry  = entry,
      _locale = i18n._locale,
    }, Message)
  end

  function I18n.__call (i18n, data)
    if type (data) ~= "table" then
      return data
    end
    local function translate (locale, t)
      locale = t.locale or locale
      if type (t) ~= "table" then
        return t
      end
      for _, v in pairs (t) do
        if type (v) == "table" and not getmetatable (v) then
          translate (locale, v)
{'fraction_non_alphanumeric': 0.10725552050473186, 'fraction_numerical': 0.019453207150368034, 'mean_word_length': 1.7855051244509517, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7283338', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1250, 'n_words': 398}