Module: I18n::Backend::KeyValue::Implementation

Includes:
Base, Flatten
Included in:
I18n::Backend::KeyValue
Defined in:
lib/active_support/vendor/i18n-0.4.1/i18n/backend/key_value.rb

Constant Summary

Constants included from Base

Base::DEPRECATED_INTERPOLATION_SYNTAX_PATTERN, Base::INTERPOLATION_SYNTAX_PATTERN, Base::RESERVED_KEYS, Base::RESERVED_KEYS_PATTERN

Constants included from Transliterator

Transliterator::DEFAULT_REPLACEMENT_CHAR

Constants included from Flatten

Flatten::FLATTEN_SEPARATOR, Flatten::SEPARATOR_ESCAPE_CHAR

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base

#load_translations, #localize, #reload!, #translate

Methods included from Transliterator

get, #transliterate

Methods included from Flatten

escape_default_separator, #flatten_keys, #flatten_translations, #links, normalize_flat_keys, #normalize_flat_keys

Instance Attribute Details

#storeObject

Returns the value of attribute store.



54
55
56
# File 'lib/active_support/vendor/i18n-0.4.1/i18n/backend/key_value.rb', line 54

def store
  @store
end

Instance Method Details

#available_localesObject



81
82
83
84
85
86
87
# File 'lib/active_support/vendor/i18n-0.4.1/i18n/backend/key_value.rb', line 81

def available_locales
  locales = @store.keys.map { |k| k =~ /\./; $` }
  locales.uniq!
  locales.compact!
  locales.map! { |k| k.to_sym }
  locales
end

#initialize(store, subtrees = true) ⇒ Object



58
59
60
# File 'lib/active_support/vendor/i18n-0.4.1/i18n/backend/key_value.rb', line 58

def initialize(store, subtrees=true)
  @store, @subtrees = store, subtrees
end

#store_translations(locale, data, options = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/active_support/vendor/i18n-0.4.1/i18n/backend/key_value.rb', line 62

def store_translations(locale, data, options = {})
  escape = options.fetch(:escape, true)
  flatten_translations(locale, data, escape, @subtrees).each do |key, value|
    key = "#{locale}.#{key}"

    case value
    when Hash
      if @subtrees && (old_value = @store[key])
        old_value = ActiveSupport::JSON.decode(old_value)
        value = old_value.deep_symbolize_keys.deep_merge!(value) if old_value.is_a?(Hash)
      end
    when Proc
      raise "Key-value stores cannot handle procs"
    end

    @store[key] = ActiveSupport::JSON.encode(value) unless value.is_a?(Symbol)
  end
end