Included Modules

I18n::Backend::ActiveRecord::Implementation

Public Instance Methods

available_locales() click to toggle source
    # File lib/i18n/backend/active_record.rb, line 14
14:         def available_locales
15:           begin
16:             Translation.available_locales
17:           rescue ::ActiveRecord::StatementInvalid
18:             []
19:           end
20:         end
store_translations(locale, data, options = {}) click to toggle source
    # File lib/i18n/backend/active_record.rb, line 22
22:         def store_translations(locale, data, options = {})
23:           escape = options.fetch(:escape, true)
24:           flatten_translations(locale, data, escape, false).each do |key, value|
25:             Translation.locale(locale).lookup(expand_keys(key)).delete_all
26:             Translation.create(:locale => locale.to_s, :key => key.to_s, :value => value)
27:           end
28:         end

Protected Instance Methods

expand_keys(key) click to toggle source

For a key :’foo.bar.baz’ return [‘foo’, ‘foo.bar’, ‘foo.bar.baz’]

    # File lib/i18n/backend/active_record.rb, line 51
51:         def expand_keys(key)
52:           key.to_s.split(FLATTEN_SEPARATOR).inject([]) do |keys, key|
53:             keys << [keys.last, key].compact.join(FLATTEN_SEPARATOR)
54:           end
55:         end
lookup(locale, key, scope = [], options = {}) click to toggle source
    # File lib/i18n/backend/active_record.rb, line 32
32:         def lookup(locale, key, scope = [], options = {})
33:           key = normalize_flat_keys(locale, key, scope, options[:separator])
34:           result = Translation.locale(locale).lookup(key).all
35: 
36:           if result.empty?
37:             nil
38:           elsif result.first.key == key
39:             result.first.value
40:           else
41:             chop_range = (key.size + FLATTEN_SEPARATOR.size)..1
42:             result = result.inject({}) do |hash, r|
43:               hash[r.key.slice(chop_range)] = r.value
44:               hash
45:             end
46:             result.deep_symbolize_keys
47:           end
48:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.