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

- old
+ new

@@ -3,13 +3,16 @@ module Pseudolocalization module I18n class Backend attr_reader :original_backend + attr_accessor :ignores def initialize(original_backend) @original_backend = original_backend + @ignores = [] + yield self if block_given? end def method_missing(name, *args, &block) if respond_to_missing?(name) original_backend.public_send(name, *args, &block) @@ -21,10 +24,30 @@ def respond_to_missing?(name, include_private = false) original_backend.respond_to?(name) || super end def translate(locale, key, options) + return original_backend.translate(locale, key, options) if key_ignored?(key) + ::Pseudolocalization::I18n::Pseudolocalizer.pseudolocalize(original_backend.translate(locale, key, options)) + end + + private + + def key_ignored?(key) + return false unless ignores + + ignores.any? do |ignore| + case ignore + when Regexp + key.to_s.match(ignore) + when String + File.fnmatch(ignore, key.to_s) + else + Rails.logger.tagged('Pseudolocalization I18n').error('Ignore type unsupported. Expects an array of (mixed) Regexp or Strings.') + false + end + end end end end end