<commit_before>module Rails
  module LocaleDetection
    mattr_accessor :locale_expiry
    @@locale_expiry = 3.months
    
    def available_locales
      I18n.available_locales
    end
  
    def default_locale
      I18n.default_locale
    end
  
    # returns the (symbolized) value passed if it's in the available_locales
    def validate_locale(locale)
      locale.to_sym if locale && available_locales.include?(locale.to_sym)
    end
  
    def locale_from_param
      validate_locale(params[:locale])
    end
  
    def locale_from_cookies
      validate_locale(cookies[:locale])
    end  
  
    def locale_from_request
      validate_locale(request.preferred_language_from(available_locales))
    end
  
    def get_locale
      locale_from_param || locale_from_cookies || locale_from_request || default_locale
    end
    
    # set I18n.locale, default_url_options[:locale] and cookies[:locale] to the value returned by
    # get_locale
    def set_locale
      default_url_options[:locale] = I18n.locale = get_locale
      
      cookies[:locale] = { :value => I18n.locale, :expires => locale_expiry.from_now }
      
      I18n.locale
    end  
  end
end<commit_msg>Make set_url_option configurable<commit_after>module Rails
  module LocaleDetection
    mattr_accessor :locale_expiry
    @@locale_expiry = 3.months
    
    mattr_accessor :set_default_url_option
    @@set_default_url_option = true
    
    def available_locales
      I18n.available_locales
    end
  
    def default_locale
      I18n.default_locale
    end
  
    # returns the (symbolized) value passed if it's in the available_locales
    def validate_locale(locale)
      locale.to_sym if locale && available_locales.include?(locale.to_sym)
    end
  
    def locale_from_param
      validate_locale(params[:locale])
    end
  
    def locale_from_cookies
      validate_locale(cookies[:locale])
    end  
  
    def locale_from_request
      validate_locale(request.preferred_language_from(available_locales))
    end
  
    def get_locale
      locale_from_param || locale_from_cookies || locale_from_request || default_locale
    end
    
    # set I18n.locale, default_url_options[:locale] and cookies[:locale] to the value returned by
    # get_locale
    def set_locale
      I18n.locale = get_locale
      
      default_url_options[:locale] = I18n.locale if set_default_url_option
      
      cookies[:locale] = { :value => I18n.locale, :expires => locale_expiry.from_now }
      
      I18n.locale
    end  
  end
end
{'fraction_non_alphanumeric': 0.06324582338902147, 'fraction_numerical': 0.011137629276054098, 'mean_word_length': 2.9794303797468356, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1336577', 'n_tokens_mistral': 820, 'n_tokens_neox': 793, 'n_words': 162}