class Dry::Schema::Messages::I18n

@api public
I18n message backend

def default_locale

Other tags:
    Api: - private
def default_locale
  super || I18n.locale || I18n.default_locale
end

def get(key, options = EMPTY_HASH)

Other tags:
    Api: - public

Returns:
  • (String) -

Parameters:
  • options (Hash) --
  • key (Symbol) --
def get(key, options = EMPTY_HASH)
  t.(key, locale: options.fetch(:locale, default_locale)) if key
end

def initialize

Other tags:
    Api: - private
def initialize
  super
  @t = I18n.method(:t)
end

def key?(key, options)

Other tags:
    Api: - public

Returns:
  • (Boolean) -
def key?(key, options)
  I18n.exists?(key, options.fetch(:locale, default_locale)) ||
    I18n.exists?(key, I18n.default_locale)
end

def merge(paths)

Other tags:
    Api: - public

Returns:
  • (Messages::I18n) -

Parameters:
  • paths (String, Array) --
def merge(paths)
  prepare(paths)
end

def prepare(paths = config.load_paths)

Other tags:
    Api: - private
def prepare(paths = config.load_paths)
  paths.each do |path|
    data = YAML.load_file(path)
    if custom_top_namespace?(path)
      top_namespace = config.top_namespace
      mapped_data = data
        .map { |k, v| [k, { top_namespace => v[DEFAULT_MESSAGES_ROOT] }] }
        .to_h
      store_translations(mapped_data)
    else
      store_translations(data)
    end
  end
  self
end

def store_translations(data)

Other tags:
    Api: - private
def store_translations(data)
  locales = data.keys.map(&:to_sym)
  I18n.available_locales |= locales
  locales.each do |locale|
    I18n.backend.store_translations(locale, data[locale.to_s])
  end
end