edge badge
Methods
I
V
W
Included Modules
Class Protected methods
include_fallbacks_module()
# File activesupport/lib/active_support/i18n_railtie.rb, line 79
def self.include_fallbacks_module
  I18n.backend.class.include(I18n::Backend::Fallbacks)
end
init_fallbacks(fallbacks)
# File activesupport/lib/active_support/i18n_railtie.rb, line 83
def self.init_fallbacks(fallbacks)
  include_fallbacks_module

  args = case fallbacks
  when ActiveSupport::OrderedOptions
    [*(fallbacks[:defaults] || []) << fallbacks[:map]].compact
  when Hash, Array
    Array.wrap(fallbacks)
  else # TrueClass
    []
  end

  I18n.fallbacks = I18n::Locale::Fallbacks.new(*args)
end
initialize_i18n(app)

Setup i18n configuration.

# File activesupport/lib/active_support/i18n_railtie.rb, line 29
def self.initialize_i18n(app)
  return if @i18n_inited

  fallbacks = app.config.i18n.delete(:fallbacks)

  # Avoid issues with setting the default_locale by disabling available locales
  # check while configuring.
  enforce_available_locales = app.config.i18n.delete(:enforce_available_locales)
  enforce_available_locales = I18n.enforce_available_locales if enforce_available_locales.nil?
  I18n.enforce_available_locales = false

  reloadable_paths = []
  app.config.i18n.each do |setting, value|
    case setting
    when :railties_load_path
      reloadable_paths = value
      app.config.i18n.load_path.unshift(*value.map(&:existent).flatten)
    when :load_path
      I18n.load_path += value
    else
      I18n.send("#{setting}=", value)
    end
  end

  init_fallbacks(fallbacks) if fallbacks && validate_fallbacks(fallbacks)

  # Restore available locales check so it will take place from now on.
  I18n.enforce_available_locales = enforce_available_locales

  directories = watched_dirs_with_extensions(reloadable_paths)
  reloader = ActiveSupport::FileUpdateChecker.new(I18n.load_path.dup, directories) do
    I18n.load_path.keep_if { |p| File.exist?(p) }
    I18n.load_path |= reloadable_paths.map(&:existent).flatten

    I18n.reload!
  end

  app.reloaders << reloader
  ActionDispatch::Reloader.to_prepare do
    reloader.execute_if_updated
    # TODO: remove the following line as soon as the return value of
    # callbacks is ignored, that is, returning `false` does not
    # display a deprecation warning or halts the callback chain.
    true
  end
  reloader.execute

  @i18n_inited = true
end
validate_fallbacks(fallbacks)
# File activesupport/lib/active_support/i18n_railtie.rb, line 98
def self.validate_fallbacks(fallbacks)
  case fallbacks
  when ActiveSupport::OrderedOptions
    !fallbacks.empty?
  when TrueClass, Array, Hash
    true
  else
    raise "Unexpected fallback type #{fallbacks.inspect}"
  end
end
watched_dirs_with_extensions(paths)
# File activesupport/lib/active_support/i18n_railtie.rb, line 109
def self.watched_dirs_with_extensions(paths)
  paths.each_with_object({}) do |path, result|
    result[path.absolute_current] = path.extensions
  end
end