lib/pseudolocalization.rb in pseudolocalization-0.9.0 vs lib/pseudolocalization.rb in pseudolocalization-0.9.1

- old
+ new

@@ -29,10 +29,17 @@ return original_backend.translate(locale, key, options) if key_ignored?(key) ::Pseudolocalization::I18n::Pseudolocalizer.pseudolocalize(original_backend.translate(locale, key, options)) end + def translations + original = original_backend.translations + original.transform_values do |locale_translations| + pseudolocalize_node(locale_translations) + end + end + private def key_ignored?(key) return false unless ignores @@ -45,9 +52,25 @@ else Rails.logger.tagged('Pseudolocalization I18n').error('Ignore type unsupported. Expects an array of (mixed) Regexp or Strings.') false end end + end + + def pseudolocalize_node(node, scope = []) + if node.is_a?(Hash) + node.each_with_object({}) do |(key, value), memo| + memo[key] = pseudolocalize_node(value, scope + [key]) + end + elsif !key_ignored?(scope.join('.')) + ::Pseudolocalization::I18n::Pseudolocalizer.pseudolocalize(node) + else + node + end + end + + def init_translations + original_backend.send(:init_translations) end end end end