Class

I18n::Backend::Simple

Inheritance
< Object

Constants

Name   Description
DEPRECATED_INTERPOLATORS = { '%d' => '{{count}}', '%s' => '{{value}}' }
INTERPOLATION_RESERVED_KEYS = %w(scope default)
MATCH = /(\\\\)?\{\{([^\}]+)\}\}/

Methods

Instance

Visibility Signature
public available_locales ()
public initialized? ()
public load_translations (*filenames)
public localize (locale, object, format = :default)
public reload! ()
public store_translations (locale, data)
public translate (locale, key, options = {})
protected deep_symbolize_keys (hash)
protected default (locale, default, options = {})
protected init_translations ()
protected interpolate (locale, string, values = {})
protected interpolate_with_deprecated_syntax (locale, string, values = {})
protected load_file (filename)
protected load_rb (filename)
protected load_yml (filename)
protected lookup (locale, key, scope = [])
protected merge_translations (locale, data)
protected pluralize (locale, entry, count)
protected translations ()

Instance Method Detail

available_locales()

Returns an array of locales for which translations are available

initialized?()

load_translations(*filenames)

Accepts a list of paths to translation files. Loads translations from plain Ruby (*.rb) or YAML files (*.yml). See load_rb and load_yml for details.

localize(locale, object, format = :default)

Acts the same as strftime, but returns a localized version of the formatted date string. Takes a key from the date/time formats translations as a format argument (e.g., :short in :’date.formats‘).

reload!()

store_translations(locale, data)

Stores translations for the given locale in memory. This uses a deep merge for the translations hash, so existing translations will be overwritten by new ones only at the deepest level of the hash.

translate(locale, key, options = {})

deep_symbolize_keys(hash)

Return a new hash with all keys and nested keys converted to symbols.

default(locale, default, options = {})

Evaluates a default translation. If the given default is a String it is used literally. If it is a Symbol it will be translated with the given options. If it is an Array the first translation yielded will be returned.

I.e., default(locale, [:foo, ‘default’]) will return default if translate(locale, :foo) does not yield a result.

init_translations()

interpolate(locale, string, values = {})

Interpolates values into a given string.

  interpolate "file {{file}} opened by \\{{user}}", :file => 'test.txt', :user => 'Mr. X'
  # => "file test.txt opened by {{user}}"

Note that you have to double escape the \ when you want to escape the {{…}} key in a string (once for the string and once for the interpolation).

interpolate_with_deprecated_syntax(locale, string, values = {})

load_file(filename)

Loads a single translations file by delegating to load_rb or load_yml depending on the file extension and directly merges the data to the existing translations. Raises I18n::UnknownFileType for all other file extensions.

load_rb(filename)

Loads a plain Ruby translations file. eval‘ing the file must yield a Hash containing translation data with locales as toplevel keys.

load_yml(filename)

Loads a YAML translations file. The data must have locales as toplevel keys.

lookup(locale, key, scope = [])

Looks up a translation from the translations hash. Returns nil if eiher key is nil, or locale, scope or key do not exist as a key in the nested translations hash. Splits keys or scopes containing dots into multiple keys, i.e. currency.format is regarded the same as %w(currency format).

merge_translations(locale, data)

Deep merges the given translations hash with the existing translations for the given locale

pluralize(locale, entry, count)

Picks a translation from an array according to English pluralization rules. It will pick the first translation if count is not equal to 1 and the second translation if it is equal to 1. Other backends can implement more flexible or complex pluralization rules.

translations()