Class: I18n::Config

### Home Classes Methods

### In Files

- lib/i18n/config.rb

### Parent

Object

### Methods

- #available_locales
- #available_locales=
- #backend
- #backend=
- #default_locale
- #default_locale=
- #default_separator
- #default_separator=
- #enforce_available_locales
- #enforce_available_locales=
- #exception_handler
- #exception_handler=
- #load_path
- #load_path=
- #locale
- #locale=
- #missing_interpolation_argument_handler
- #missing_interpolation_argument_handler=

### Class/Module Index

Quicksearch

- I18n
- I18n::ArgumentError
- I18n::Backend
- I18n::Backend::Base
- I18n::Backend::Cache
- I18n::Backend::Cascade
- I18n::Backend::Chain
- I18n::Backend::Chain::Implementation
- I18n::Backend::Fallbacks
- I18n::Backend::Flatten
- I18n::Backend::Gettext
- I18n::Backend::Gettext::PoData
- I18n::Backend::InterpolationCompiler
- I18n::Backend::InterpolationCompiler::Compiler
- I18n::Backend::KeyValue
- I18n::Backend::KeyValue::Implementation
- I18n::Backend::Memoize
- I18n::Backend::Metadata
- I18n::Backend::Pluralization
- I18n::Backend::Simple
- I18n::Backend::Simple::Implementation
- I18n::Config
- I18n::ExceptionHandler
- I18n::Gettext
- I18n::Gettext::Helpers
- I18n::InvalidLocale
- I18n::InvalidLocaleData
- I18n::InvalidPluralizationData
- I18n::Locale
- I18n::Locale::Fallbacks
- I18n::Locale::Tag
- I18n::Locale::Tag::Parents
- I18n::Locale::Tag::Rfc4646
- I18n::Locale::Tag::Rfc4646::Parser
- I18n::Locale::Tag::Simple
- I18n::MissingInterpolationArgument
- I18n::MissingTranslation
- I18n::MissingTranslation::Base
- I18n::MissingTranslationData
- I18n::ReservedInterpolationKey
- I18n::Tests
- I18n::Tests::Basics
- I18n::Tests::Defaults
- I18n::Tests::Link
- I18n::Tests::Localization
- I18n::Tests::Lookup
- I18n::Tests::Pluralization
- I18n::Tests::Procs
- I18n::UnknownFileType
- GetText
- GetText::PoParser
- Hash
- Kernel
- KeyError
- String

No matching classes.

# I18n::Config

### Public Instance Methods

available_locales() click to toggle source

Returns an array of locales for which translations are available. Unless you explicitely set these through I18n.available_locales= the call will be delegated to the backend.

    # File lib/i18n/config.rb, line 39
    def available_locales
      @@available_locales ||= nil
      @@available_locales || backend.available_locales
    end

available_locales=(locales) click to toggle source

Sets the available locales.

    # File lib/i18n/config.rb, line 45
    def available_locales=(locales)
      @@available_locales = Array(locales).map { |locale| locale.to_sym }
      @@available_locales = nil if @@available_locales.empty?
    end

backend() click to toggle source

Returns the current backend. Defaults to +Backend::Simple+.

    # File lib/i18n/config.rb, line 16
    def backend
      @@backend ||= Backend::Simple.new
    end

backend=(backend) click to toggle source

Sets the current backend. Used to set a custom backend.

    # File lib/i18n/config.rb, line 21
    def backend=(backend)
      @@backend = backend
    end

default_locale() click to toggle source

Returns the current default locale. Defaults to :'en'

    # File lib/i18n/config.rb, line 26
    def default_locale
      @@default_locale ||= :en
    end

default_locale=(locale) click to toggle source

Sets the current default locale. Used to set a custom default locale.

    # File lib/i18n/config.rb, line 31
    def default_locale=(locale)
      I18n.enforce_available_locales!(locale)
      @@default_locale = locale.to_sym rescue nil
    end

default_separator() click to toggle source

Returns the current default scope separator. Defaults to '.'

    # File lib/i18n/config.rb, line 51
    def default_separator
      @@default_separator ||= '.'
    end

default_separator=(separator) click to toggle source

Sets the current default scope separator.

    # File lib/i18n/config.rb, line 56
    def default_separator=(separator)
      @@default_separator = separator
    end

enforce_available_locales() click to toggle source

Deprecated

  this will default to true in the future

Defaults to nil so that it triggers the deprecation warning

    # File lib/i18n/config.rb, line 113
    def enforce_available_locales
      defined?(@@enforce_available_locales) ? @@enforce_available_locales : nil
    end

enforce_available_locales=(enforce_available_locales) click to toggle source

    # File lib/i18n/config.rb, line 117
    def enforce_available_locales=(enforce_available_locales)
      @@enforce_available_locales = enforce_available_locales
    end

exception_handler() click to toggle source

Return the current exception handler. Defaults to :default_exception_handler.

    # File lib/i18n/config.rb, line 61
    def exception_handler
      @@exception_handler ||= ExceptionHandler.new
    end

exception_handler=(exception_handler) click to toggle source

Sets the exception handler.

    # File lib/i18n/config.rb, line 66
    def exception_handler=(exception_handler)
      @@exception_handler = exception_handler
    end

load_path() click to toggle source

Allow clients to register paths providing translation data sources. The backend defines acceptable sources.

E.g. the provided SimpleBackend accepts a list of paths to translation files which are either named *.rb and contain plain Ruby Hashes or are named *.yml and contain YAML data. So for the SimpleBackend clients may register translation files like this:

    I18n.load_path << 'path/to/locale/en.yml'

    # File lib/i18n/config.rb, line 101
    def load_path
      @@load_path ||= []
    end

load_path=(load_path) click to toggle source

Sets the load path instance. Custom implementations are expected to behave like a Ruby Array.

    # File lib/i18n/config.rb, line 107
    def load_path=(load_path)
      @@load_path = load_path
    end

locale() click to toggle source

The only configuration value that is not global and scoped to thread is :locale. It defaults to the default_locale.

    # File lib/i18n/config.rb, line 5
    def locale
      @locale ||= default_locale
    end

locale=(locale) click to toggle source

Sets the current locale pseudo-globally, i.e. in the Thread.current hash.

    # File lib/i18n/config.rb, line 10
    def locale=(locale)
      I18n.enforce_available_locales!(locale)
      @locale = locale.to_sym rescue nil
    end

missing_interpolation_argument_handler() click to toggle source

Returns the current handler for situations when interpolation argument is missing. MissingInterpolationArgument will be raised by default.

    # File lib/i18n/config.rb, line 72
    def missing_interpolation_argument_handler
      @@missing_interpolation_argument_handler ||= lambda do |missing_key, provided_hash, string|
        raise MissingInterpolationArgument.new(missing_key, provided_hash, string)
      end
    end

missing_interpolation_argument_handler=(exception_handler) click to toggle source

Sets the missing interpolation argument handler. It can be any object that responds to call. The arguments that will be passed to call are the same as for MissingInterpolationArgument initializer. Use `Proc.new` if you don't care about arity.

## Example:

You can supress raising an exception and return string instead:

    I18n.config.missing_interpolation_argument_handler = Proc.new do |key|
      "#{key} is missing"
    end

    # File lib/i18n/config.rb, line 89
    def missing_interpolation_argument_handler=(exception_handler)
      @@missing_interpolation_argument_handler = exception_handler
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.