<commit_before>module I18n
  module Backend
    class Chain # < Simple extend this to get the default method from the Simple backend?
      
      # Change this to a) accept any number of backends and b) accept classes.
      # When classes are passed instantiate them and add the instances as backends.
      # Return the added backends from #add.
      #
      # Add an initialize method that accepts the same arguments and passes them
      # to #add, so we could:
      #   I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Spec, I18n::Backend::Simple)
      def add(backend)
        backends << backend
      end
    
      def translate(locale, key, options = {})
        # For bulk translation:
        # If the key is an array we need to call #translate for each of the
        # keys and collect the results.
        #
        # Exceptions:
        # Make sure that we catch MissingTranslationData exceptions and raise
        # one in the end when no translation was found at all.
        backends.inject({}) do |result, backend|
          # For defaults:
          # Never pass any default option to the backends but instead implement our own default
          # mechanism (e.g. symbols as defaults would need to be passed to the whole chain to
          # be translated).
          #
          # For namespace lookup: 
          # Only return if the result is not a hash OR count is not present, otherwise merge them.
          # So in effect the count variable would control whether we have a namespace lookup or a 
          # pluralization going on.
          begin
            translation = backend.translate(locale, key, options) 
            if namespace_lookup?(translation, options)
              result.merge! translation
            elsif translation
              return translation 
            end
          rescue I18n::MissingTranslationData
          end
          result
        end
      end
    
      protected
        def backends
          @backends ||= []
        end
        
        def namespace_lookup?(result, options)
          result.is_a?(Hash) and not options.has_key?(:count)
        end
    end
  end
end<commit_msg>rename result variable to namespace<commit_after>module I18n
  module Backend
    class Chain # < Simple extend this to get the default method from the Simple backend?
      
      # Change this to a) accept any number of backends and b) accept classes.
      # When classes are passed instantiate them and add the instances as backends.
      # Return the added backends from #add.
      #
      # Add an initialize method that accepts the same arguments and passes them
      # to #add, so we could:
      #   I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Spec, I18n::Backend::Simple)
      def add(backend)
        backends << backend
      end
    
      def translate(locale, key, options = {})
        # For bulk translation:
        # If the key is an array we need to call #translate for each of the
        # keys and collect the results.
        #
        # Exceptions:
        # Make sure that we catch MissingTranslationData exceptions and raise
        # one in the end when no translation was found at all.
        backends.inject({}) do |namespace, backend|
          # For defaults:
          # Never pass any default option to the backends but instead implement our own default
          # mechanism (e.g. symbols as defaults would need to be passed to the whole chain to
          # be translated).
          #
          # For namespace lookup: 
          # Only return if the result is not a hash OR count is not present, otherwise merge them.
          # So in effect the count variable would control whether we have a namespace lookup or a 
          # pluralization going on.
          begin
            translation = backend.translate(locale, key, options) 
            if namespace_lookup?(translation, options)
              namespace.merge! translation
            elsif translation
              return translation 
            end
          rescue I18n::MissingTranslationData
          end
          namespace
        end
      end
    
      protected
        def backends
          @backends ||= []
        end
        
        def namespace_lookup?(result, options)
          result.is_a?(Hash) and not options.has_key?(:count)
        end
    end
  end
end
{'fraction_non_alphanumeric': 0.056357388316151204, 'fraction_numerical': 0.005498281786941581, 'mean_word_length': 1.9519945909398242, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7556573', 'n_tokens_mistral': 1061, 'n_tokens_neox': 1053, 'n_words': 473}