Skip to content

Commit

Permalink
Make interpolations variable regex configurable
Browse files Browse the repository at this point in the history
For better `it` gem support. Refs #361
  • Loading branch information
glebm committed Mar 25, 2022
1 parent 33ec754 commit 6a2e995
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/i18n/tasks/interpolations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@

module I18n::Tasks
module Interpolations
VARIABLE_REGEX = /%{[^}]+}/.freeze
class << self
attr_accessor :variable_regex
end
@variable_regex = /%{[^}]+}/.freeze

def inconsistent_interpolations(locales: nil, base_locale: nil) # rubocop:disable Metrics/AbcSize
locales ||= self.locales
base_locale ||= self.base_locale
result = empty_forest
variable_regex = I18n::Tasks::Interpolations.variable_regex

data[base_locale].key_values.each do |key, value|
next if !value.is_a?(String) || ignore_key?(key, :inconsistent_interpolations)

base_vars = Set.new(value.scan(VARIABLE_REGEX))
base_vars = Set.new(value.scan(variable_regex))
(locales - [base_locale]).each do |current_locale|
node = data[current_locale].first.children[key]
next unless node&.value.is_a?(String)

if base_vars != Set.new(node.value.scan(VARIABLE_REGEX))
if base_vars != Set.new(node.value.scan(variable_regex))
result.merge!(node.walk_to_root.reduce(nil) { |c, p| [p.derive(children: c)] })
end
end
Expand Down

0 comments on commit 6a2e995

Please sign in to comment.