Skip to content

Commit

Permalink
Merge pull request #528 from krzysiek1507/feature/optimize-normalize_…
Browse files Browse the repository at this point in the history
…flat_keys

Optimize normalize_flat_keys
  • Loading branch information
radar committed Jun 4, 2020
2 parents a8f4fdc + 4031429 commit c1ec567
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/i18n/backend/flatten.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ module Flatten
# and creates way less objects than the one at I18n.normalize_keys.
# It also handles escaping the translation keys.
def self.normalize_flat_keys(locale, key, scope, separator)
keys = [scope, key].flatten.compact
keys = [scope, key]
keys.flatten!
keys.compact!

separator ||= I18n.default_separator

if separator != FLATTEN_SEPARATOR
keys.map! do |k|
k.to_s.tr("#{FLATTEN_SEPARATOR}#{separator}",
"#{SEPARATOR_ESCAPE_CHAR}#{FLATTEN_SEPARATOR}")
end
from_str = "#{FLATTEN_SEPARATOR}#{separator}"
to_str = "#{SEPARATOR_ESCAPE_CHAR}#{FLATTEN_SEPARATOR}"

keys.map! { |k| k.to_s.tr from_str, to_str }
end

keys.join(".")
Expand Down

0 comments on commit c1ec567

Please sign in to comment.