Sha256: fb2effbf08a90c30aa68619fcd05f3c39508fe6f406d62d0aa085d0215b37e65

Contents?: true

Size: 615 Bytes

Versions: 10

Compression:

Stored size: 615 Bytes

Contents

module I18n
  module Backend
    module Flatten

      # Nest keys for flatten (dotted) hashes
      #   IN:  { "hello.world" => "hello world" }
      #   OUT: { :hello => { :world => "hello world" } }
      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

    end

    include Flatten
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
exvo_globalize-0.6.0 lib/exvo_globalize/backend/flatten.rb
exvo_globalize-0.5.6 lib/exvo_globalize/backend/flatten.rb
exvo_globalize-0.5.5 lib/exvo_globalize/backend/flatten.rb
exvo_globalize-0.5.4 lib/exvo_globalize/backend/flatten.rb
exvo_globalize-0.5.3 lib/exvo_globalize/backend/flatten.rb
exvo_globalize-0.5.2 lib/exvo_globalize/backend/flatten.rb
exvo_globalize-0.5.1 lib/exvo_globalize/backend/flatten.rb
exvo_globalize-0.5.0 lib/exvo_globalize/backend/flatten.rb
exvo_globalize-0.4.0 lib/exvo_globalize/backend/flatten.rb
exvo_globalize-0.3.2 lib/exvo_globalize/backend/flatten.rb