123456789_123456789_123456789_123456789_123456789_

Class: I18n::Railtie

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Rails::Railtie
Defined in: activesupport/lib/active_support/i18n_railtie.rb

Constant Summary

::Rails::Railtie - Inherited

ABSTRACT_RAILTIES

Class Attribute Summary

Class Method Summary

::Rails::Railtie - Inherited

.configure

Allows you to configure the railtie.

.console, .generators, .inherited,
.instance

Since ::Rails::Railtie cannot be instantiated, any methods that call instance are intended to be called only on subclasses of a Railtie.

.railtie_name, .rake_tasks, .runner, .server, .subclasses, .increment_load_index, .generate_railtie_name,
.method_missing

If the class method does not have a method, then send the method call to the Railtie instance.

.register_block_for

receives an instance variable identifier, set the variable value if is blank and append given block to value, which will be used later in #each_registered_block(type, &block).

.respond_to_missing?, .<=>, .new

::ActiveSupport::DescendantsTracker - Extended

Instance Attribute Summary

::Rails::Railtie - Inherited

#config

This is used to create the config object on Railties, an instance of Railtie::Configuration, that is used by Railties and Application to store related configuration.

#railtie_name

Instance Method Summary

Constructor Details

This class inherits a constructor from Rails::Railtie

Class Method Details

.include_fallbacks_module

[ GitHub ]

  
# File 'activesupport/lib/active_support/i18n_railtie.rb', line 103

def self.include_fallbacks_module
  I18n.backend.class.include(I18n::Backend::Fallbacks)
end

.init_fallbacks(fallbacks)

[ GitHub ]

  
# File 'activesupport/lib/active_support/i18n_railtie.rb', line 107

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
      [I18n.default_locale]
    end

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

.initialize_i18n(app)

Setup i18n configuration.

[ GitHub ]

  
# File 'activesupport/lib/active_support/i18n_railtie.rb', line 35

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.flat_map(&:existent))
    when :load_path
      I18n.load_path += value
    when :raise_on_missing_translations
      strict = value == :strict
      setup_raise_on_missing_translations_config(app, strict)
    else
      I18n.public_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

  if app.config.reloading_enabled?
    directories = watched_dirs_with_extensions(reloadable_paths)
    root_load_paths = I18n.load_path.select { |path| path.to_s.start_with?(Rails.root.to_s) }
    reloader = app.config.file_watcher.new(root_load_paths, directories) do
      I18n.load_path.delete_if { |path| path.to_s.start_with?(Rails.root.to_s) && !File.exist?(path) }
      I18n.load_path |= reloadable_paths.flat_map(&:existent)
    end

    app.reloaders << reloader
    app.reloader.to_run do
      reloader.execute_if_updated { require_unload_lock! }
    end
  end

  @i18n_inited = true
end

.setup_raise_on_missing_translations_config(app, strict)

[ GitHub ]

  
# File 'activesupport/lib/active_support/i18n_railtie.rb', line 84

def self.setup_raise_on_missing_translations_config(app, strict)
  ActiveSupport.on_load(:action_view) do
    ActionView::Helpers::TranslationHelper.raise_on_missing_translations = app.config.i18n.raise_on_missing_translations
  end

  ActiveSupport.on_load(:active_model_translation) do
    ActiveModel::Translation.raise_on_missing_translations = app.config.i18n.raise_on_missing_translations if strict
  end

  if app.config.i18n.raise_on_missing_translations &&
      I18n.exception_handler.is_a?(I18n::ExceptionHandler) # Only override the i18n gem's default exception handler.

    I18n.exception_handler = ->(exception, *) {
      exception = exception.to_exception if exception.is_a?(I18n::MissingTranslation)
      raise exception
    }
  end
end

.validate_fallbacks(fallbacks)

[ GitHub ]

  
# File 'activesupport/lib/active_support/i18n_railtie.rb', line 123

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)

[ GitHub ]

  
# File 'activesupport/lib/active_support/i18n_railtie.rb', line 134

def self.watched_dirs_with_extensions(paths)
  paths.each_with_object({}) do |path, result|
    result[path.absolute_current] = path.extensions
  end
end