Included Modules

Class Index [+]

Quicksearch

I18n::Backend::Simple::Implementation

Public Instance Methods

available_locales() click to toggle source

Get available locales from the translations hash

    # File lib/i18n/backend/simple.rb, line 39
39:         def available_locales
40:           init_translations unless initialized?
41:           translations.inject([]) do |locales, (locale, data)|
42:             locales << locale unless (data.keys - [:i18n]).empty?
43:             locales
44:           end
45:         end
initialized?() click to toggle source
    # File lib/i18n/backend/simple.rb, line 23
23:         def initialized?
24:           @initialized ||= false
25:         end
reload!() click to toggle source

Clean up translations hash and set initialized to false on reload!

    # File lib/i18n/backend/simple.rb, line 48
48:         def reload!
49:           @initialized = false
50:           @translations = nil
51:           super
52:         end
store_translations(locale, data, options = {}) click to toggle source

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.

    # File lib/i18n/backend/simple.rb, line 31
31:         def store_translations(locale, data, options = {})
32:           locale = locale.to_sym
33:           translations[locale] ||= {}
34:           data = data.deep_symbolize_keys
35:           translations[locale].deep_merge!(data)
36:         end

Protected Instance Methods

init_translations() click to toggle source
    # File lib/i18n/backend/simple.rb, line 56
56:         def init_translations
57:           load_translations
58:           @initialized = true
59:         end
lookup(locale, key, scope = [], options = {}) click to toggle source

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).

    # File lib/i18n/backend/simple.rb, line 70
70:         def lookup(locale, key, scope = [], options = {})
71:           init_translations unless initialized?
72:           keys = I18n.normalize_keys(locale, key, scope, options[:separator])
73: 
74:           keys.inject(translations) do |result, _key|
75:             _key = _key.to_sym
76:             return nil unless result.is_a?(Hash) && result.has_key?(_key)
77:             result = result[_key]
78:             result = resolve(locale, _key, result, options.merge(:scope => nil)) if result.is_a?(Symbol)
79:             result
80:           end
81:         end
translations() click to toggle source
    # File lib/i18n/backend/simple.rb, line 61
61:         def translations
62:           @translations ||= {}
63:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.