<commit_before>module RoutingFilter
  class Locale < Base

    def around_recognize(path, env, &block)
      if ::Refinery::I18n.enabled?
        locale = nil
        if path =~ %r{^\/#{::Refinery::I18n.locales.keys.join('|')}\/}
          if path !~ %r{^/(admin|refinery|wymiframe)}
            path.sub! %r(^/(([a-zA-Z\-_])*)(?=/|$)) do
              locale = $1
              ::I18n.locale = locale
              ''
            end
          end
        else
          ::I18n.locale = ::Refinery::I18n.current_locale
        end

        returning yield do |params|
          unless path =~ %r{^/(admin|refinery|wymiframe)} or ::I18n.locale == ::Refinery::I18n.default_locale
            params[:locale] = (locale.presence || ::Refinery::I18n.current_locale)
          end
        end
      else
        returning yield do |result|
          result
        end
      end
    end

    def around_generate(*args, &block)
      if ::Refinery::I18n.enabled?
        locale = args.extract_options!.delete(:locale) || ::I18n.locale
        returning yield do |result|
          if (locale != ::Refinery::I18n.default_locale and result !~ %r{^/(refinery|wymiframe)})
            result.sub!(%r(^(http.?://[^/]*)?(.*))){ "#{$1}/#{locale}#{$2}" }
          end
          result
        end
      else
        returning yield do |result|
          result
        end
      end
    end

  end
end
<commit_msg>allow login again in the default locale<commit_after>module RoutingFilter
  class Locale < Base

    def around_recognize(path, env, &block)
      if ::Refinery::I18n.enabled?
        locale = nil
        if path =~ %r{^\/#{::Refinery::I18n.locales.keys.join('|')}\/}
          if path !~ %r{^/(sessions?|admin|refinery|wymiframe)}
            path.sub! %r(^/(([a-zA-Z\-_])*)(?=/|$)) do
              locale = $1
              ::I18n.locale = locale
              ''
            end
          end
        else
          ::I18n.locale = ::Refinery::I18n.current_locale
        end

        returning yield do |params|
          unless path =~ %r{^/(admin|refinery|wymiframe)} or ::I18n.locale == ::Refinery::I18n.default_locale
            params[:locale] = (locale.presence || ::Refinery::I18n.current_locale)
          end
        end
      else
        returning yield do |result|
          result
        end
      end
    end

    def around_generate(*args, &block)
      if ::Refinery::I18n.enabled?
        locale = args.extract_options!.delete(:locale) || ::I18n.locale
        returning yield do |result|
          if (locale != ::Refinery::I18n.default_locale and result !~ %r{^/(refinery|wymiframe)})
            result.sub!(%r(^(http.?://[^/]*)?(.*))){ "#{$1}/#{locale}#{$2}" }
          end
          result
        end
      else
        returning yield do |result|
          result
        end
      end
    end

  end
end

{'fraction_non_alphanumeric': 0.15574348132487667, 'fraction_numerical': 0.017618040873854827, 'mean_word_length': 1.8305084745762712, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4540020', 'n_tokens_mistral': 947, 'n_tokens_neox': 902, 'n_words': 186}