Module: I18n::Backend::KeyValue::Implementation
- Included in:
- I18n::Backend::KeyValue
- Defined in:
- lib/i18n/backend/key_value.rb
Constant Summary
Constants included from Transliterator
Transliterator::DEFAULT_REPLACEMENT_CHAR
Constants included from Flatten
Flatten::FLATTEN_SEPARATOR, Flatten::SEPARATOR_ESCAPE_CHAR
Instance Attribute Summary collapse
-
#store ⇒ Object
Returns the value of attribute store.
Instance Method Summary collapse
- #available_locales ⇒ Object
- #initialize(store, subtrees = true) ⇒ Object
- #store_translations(locale, data, options = EMPTY_HASH) ⇒ Object
Methods included from Base
#exists?, #load_translations, #localize, #reload!, #translate
Methods included from Transliterator
Methods included from Flatten
escape_default_separator, #flatten_keys, #flatten_translations, #links, normalize_flat_keys, #normalize_flat_keys
Instance Attribute Details
#store ⇒ Object
Returns the value of attribute store.
71 72 73 |
# File 'lib/i18n/backend/key_value.rb', line 71 def store @store end |
Instance Method Details
#available_locales ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/i18n/backend/key_value.rb', line 98 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
75 76 77 |
# File 'lib/i18n/backend/key_value.rb', line 75 def initialize(store, subtrees=true) @store, @subtrees = store, subtrees end |
#store_translations(locale, data, options = EMPTY_HASH) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/i18n/backend/key_value.rb', line 79 def store_translations(locale, data, = EMPTY_HASH) escape = .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 = 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] = JSON.encode(value) unless value.is_a?(Symbol) end end |