diff --git a/lib/i18n.rb b/lib/i18n.rb index a30d169a..ba29a1e1 100644 --- a/lib/i18n.rb +++ b/lib/i18n.rb @@ -389,7 +389,7 @@ def normalize_key(key, separator) @@normalized_key_cache[separator][key] ||= case key when Array - key.map { |k| normalize_key(k, separator) }.flatten + key.flat_map { |k| normalize_key(k, separator) } else keys = key.to_s.split(separator) keys.delete('') diff --git a/lib/i18n/locale/fallbacks.rb b/lib/i18n/locale/fallbacks.rb index 0a791c65..dee99172 100644 --- a/lib/i18n/locale/fallbacks.rb +++ b/lib/i18n/locale/fallbacks.rb @@ -60,7 +60,7 @@ def initialize(*mappings) end def defaults=(defaults) - @defaults = defaults.map { |default| compute(default, false) }.flatten + @defaults = defaults.flat_map { |default| compute(default, false) } end attr_reader :defaults @@ -84,13 +84,15 @@ def map(mappings) protected def compute(tags, include_defaults = true, exclude = []) - result = Array(tags).collect do |tag| + result = Array(tags).flat_map do |tag| tags = I18n::Locale::Tag.tag(tag).self_and_parents.map! { |t| t.to_sym } - exclude tags.each { |_tag| tags += compute(@map[_tag], false, exclude + tags) if @map[_tag] } tags - end.flatten + end result.push(*defaults) if include_defaults - result.uniq.compact + result.uniq! + result.compact! + result end end end diff --git a/lib/i18n/locale/tag/parents.rb b/lib/i18n/locale/tag/parents.rb index ec53060f..6283e667 100644 --- a/lib/i18n/locale/tag/parents.rb +++ b/lib/i18n/locale/tag/parents.rb @@ -3,18 +3,20 @@ module Locale module Tag module Parents def parent - @parent ||= begin - segs = to_a.compact - segs.length > 1 ? self.class.tag(*segs[0..(segs.length-2)].join('-')) : nil - end + @parent ||= + begin + segs = to_a + segs.compact! + segs.length > 1 ? self.class.tag(*segs[0..(segs.length - 2)].join('-')) : nil + end end def self_and_parents - @self_and_parents ||= [self] + parents + @self_and_parents ||= [self].concat parents end def parents - @parents ||= ([parent] + (parent ? parent.parents : [])).compact + @parents ||= parent ? [parent].concat(parent.parents) : [] end end end diff --git a/lib/i18n/locale/tag/simple.rb b/lib/i18n/locale/tag/simple.rb index 68642a12..6d9ab565 100644 --- a/lib/i18n/locale/tag/simple.rb +++ b/lib/i18n/locale/tag/simple.rb @@ -19,7 +19,7 @@ def initialize(*tag) end def subtags - @subtags = tag.to_s.split('-').map { |subtag| subtag.to_s } + @subtags = tag.to_s.split('-').map!(&:to_s) end def to_sym