module I18n::Processes::Data

Constants

DATA_DEFAULTS

Public Instance Methods

build_tree(hash) click to toggle source
# File lib/i18n/processes/data.rb, line 48
def build_tree(hash)
  I18n::Processes::Data::Tree::Siblings.from_nested_hash(hash)
end
data() click to toggle source

I18n data provider @see I18n::Processes::Data::FileSystem

# File lib/i18n/processes/data.rb, line 13
def data
  @data ||= begin
    data_config = (config[:data] || {}).deep_symbolize_keys
    data_config[:base_locale] = base_locale
    data_config[:locales] = config[:locales]
    adapter_class = data_config[:adapter].presence || data_config[:class].presence || DATA_DEFAULTS[:adapter]
    adapter_class = adapter_class.to_s
    adapter_class = 'I18n::Processes::Data::FileSystem' if adapter_class == 'file_system'
    data_config.except!(:adapter, :class)
    ActiveSupport::Inflector.constantize(adapter_class).new data_config
  end
end
data_forest(locales = self.locales) click to toggle source
# File lib/i18n/processes/data.rb, line 30
def data_forest(locales = self.locales)
  locales.inject(empty_forest) do |tree, locale|
    tree.merge! data[locale]
  end
end
empty_forest() click to toggle source
# File lib/i18n/processes/data.rb, line 26
def empty_forest
  I18n::Processes::Data::Tree::Siblings.new
end
external_key?(key, locale = base_locale) click to toggle source
# File lib/i18n/processes/data.rb, line 62
def external_key?(key, locale = base_locale)
  data.external(locale)[locale.to_s][key]
end
key_value?(key, locale = base_locale) click to toggle source

whether the value for key exists in locale (defaults: base_locale)

# File lib/i18n/processes/data.rb, line 58
def key_value?(key, locale = base_locale)
  !t(key, locale).nil?
end
node(key, locale = base_locale) click to toggle source
# File lib/i18n/processes/data.rb, line 44
def node(key, locale = base_locale)
  data[locale]["#{locale}.#{key}"]
end
non_normalized_paths(locales: nil) click to toggle source

@param [Array<String>] locales locales to check. Default: all. @return [Array<String>] paths to data that requires normalization

# File lib/i18n/processes/data.rb, line 83
def non_normalized_paths(locales: nil)
  Array(locales || self.locales).flat_map { |locale| data.non_normalized_paths(locale) }
end
normalize_store!(locales: nil, force_pattern_router: false) click to toggle source

Normalize all the locale data in the store (by writing to the store).

@param [Array<String>] locales locales to normalize. Default: all. @param [Boolean] force_pattern_router Whether to use pattern router regardless of the config.

# File lib/i18n/processes/data.rb, line 70
def normalize_store!(locales: nil, force_pattern_router: false)
  locales ||= self.locales
  router = force_pattern_router ? ::I18n::Processes::Data::Router::PatternRouter.new(data, data.config) : data.router
  data.with_router(router) do
    Array(locales).each do |target_locale|
      # The store handles actual normalization:
      data[target_locale] = data[target_locale]
    end
  end
end
t(key, locale = base_locale) click to toggle source
# File lib/i18n/processes/data.rb, line 36
def t(key, locale = base_locale)
  data.t(key, locale)
end
t_proc(locale = base_locale) click to toggle source
# File lib/i18n/processes/data.rb, line 52
def t_proc(locale = base_locale)
  @t_proc         ||= {}
  @t_proc[locale] ||= proc { |key| t(key, locale) }
end
tree(sel) click to toggle source
# File lib/i18n/processes/data.rb, line 40
def tree(sel)
  data[split_key(sel, 2).first][sel].try(:children)
end