Sha256: 4fb75624288f57c1e44b8f5554fa4eb081d3b94f2a593f6f071a97b85021aefe
Contents?: true
Size: 611 Bytes
Versions: 3
Compression:
Stored size: 611 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_s => nest_translations(value) } else { key.to_s => value } end end end.inject(&:deep_merge) end end include Flatten end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
exvo_globalize-0.3.1 | lib/exvo_globalize/backend/flatten.rb |
exvo_globalize-0.3.0 | lib/exvo_globalize/backend/flatten.rb |
exvo_globalize-0.2.1 | lib/exvo_globalize/backend/flatten.rb |