Module: I18n::Backend::KeyValue::Implementation
- Includes:
- Base, Flatten
- Included in:
- I18n::Backend::KeyValue
- Defined in:
- lib/i18n/backend/key_value.rb
Constant Summary
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)
-
- (Object) store
Returns the value of attribute store.
Instance Method Summary (collapse)
- - (Object) available_locales
- - (Object) initialize(store, subtrees = true)
- - (Object) store_translations(locale, data, options = {})
Methods included from Base
#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
- (Object) store
Returns the value of attribute store
53 54 55 |
# File 'lib/i18n/backend/key_value.rb', line 53 def store @store end |
Instance Method Details
- (Object) available_locales
80 81 82 83 84 85 86 |
# File 'lib/i18n/backend/key_value.rb', line 80 def available_locales locales = @store.keys.map { |k| k =~ /\./; $` } locales.uniq! locales.compact! locales.map! { |k| k.to_sym } locales end |
- (Object) initialize(store, subtrees = true)
57 58 59 |
# File 'lib/i18n/backend/key_value.rb', line 57 def initialize(store, subtrees=true) @store, @subtrees = store, subtrees end |
- (Object) store_translations(locale, data, options = {})
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/i18n/backend/key_value.rb', line 61 def store_translations(locale, data, = {}) 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 = 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 |