Module: I18n::Backend::Flatten

Included in:
I18n::Backend, GlobalizeStore::Implementation
Defined in:
lib/exvo_globalize/backend/flatten.rb

Instance Method Summary collapse

Instance Method Details

#nest_translations(hash) ⇒ Object

Nest keys for flatten (dotted) hashes

IN:  { "hello.world" => "hello world" }
OUT: { :hello => { :world => "hello world" } }


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/exvo_globalize/backend/flatten.rb', line 8

def nest_translations(hash)
  hash.map do |main_key, main_value|
    main_key.to_s.split(".").reverse.inject(main_value) do |value, key|
      if value.is_a?(Hash)
        { key.to_sym => nest_translations(value) }
      else
        { key.to_sym => value }
      end
    end
  end.inject(&:deep_merge)
end