Sha256: cf8d368854320621ca8614d91b42bc83294348ae406c7e34ed492e0618a81c1c
Contents?: true
Size: 1.02 KB
Versions: 1
Compression:
Stored size: 1.02 KB
Contents
# frozen_string_literal: true module I18n::Tasks module Interpolations VARIABLE_REGEX = /%{[^}]+}/ def inconsistent_interpolations(locales: nil, base_locale: nil) # rubocop:disable Metrics/AbcSize locales ||= self.locales base_locale ||= self.base_locale result = empty_forest 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)) (locales - [base_locale]).each do |current_locale| node = data[current_locale].first.children[key] next unless node&.value&.is_a?(String) vars = node.value.scan(VARIABLE_REGEX) unless vars.size == base_vars.size && vars.all? { |v| base_vars.include?(v) } result.merge!(node.walk_to_root.reduce(nil) { |c, p| [p.derive(children: c)] }) end end end result.each { |root| root.data[:type] = :inconsistent_interpolations } result end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
i18n-tasks-0.9.26 | lib/i18n/tasks/interpolations.rb |