<commit_before>require 'casino'
require 'http_accept_language'

class CASino::ApplicationController < ::ApplicationController
  include ApplicationHelper

  layout 'application'
  before_filter :set_locale

  def cookies
    super
  end

  protected
  def processor(processor_name, listener_name = nil)
    listener_name ||= processor_name
    listener = CASino.const_get(:"#{listener_name}Listener").new(self)
    @processor = CASino.const_get(:"#{processor_name}Processor").new(listener)
  end

  def set_locale
    I18n.locale = extract_locale_from_accept_language_header || I18n.default_locale
  end

  def extract_locale_from_accept_language_header
    if request.env['HTTP_ACCEPT_LANGUAGE']
      http_accept_language.preferred_language_from(I18n.available_locales)
    end
  end

  def http_accept_language
    HttpAcceptLanguage::Parser.new request.env['HTTP_ACCEPT_LANGUAGE']
  end
end<commit_msg>add set locale by URL<commit_after>require 'casino'
require 'http_accept_language'

class CASino::ApplicationController < ::ApplicationController
  include ApplicationHelper

  layout 'application'
  before_filter :set_locale

  def cookies
    super
  end

  protected
  def processor(processor_name, listener_name = nil)
    listener_name ||= processor_name
    listener = CASino.const_get(:"#{listener_name}Listener").new(self)
    @processor = CASino.const_get(:"#{processor_name}Processor").new(listener)
  end

  def available_locale
    ['de','en']
  end

  def set_locale
    locale = if params[:service] and params[:service].match(/.*[?&]locale=([^&]+)(&|$)/)
               result = params[:service].match(/.*[?&]locale=([^&]+)(&|$)/)
               result[1]
             elsif request.env['HTTP_ACCEPT_LANGUAGE']
               http_accept_language.preferred_language_from(I18n.available_locales)
             end
    I18n.locale = available_locale.include?(locale) ? locale : I18n.default_locale
  end

  def extract_locale_from_accept_language_header
    if request.env['HTTP_ACCEPT_LANGUAGE']
      http_accept_language.preferred_language_from(I18n.available_locales)
    end
  end

  def http_accept_language
    HttpAcceptLanguage::Parser.new request.env['HTTP_ACCEPT_LANGUAGE']
  end
end
{'fraction_non_alphanumeric': 0.10085933966530981, 'fraction_numerical': 0.0067842605156037995, 'mean_word_length': 4.571788413098237, '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': '6639487', 'n_tokens_mistral': 702, 'n_tokens_neox': 676, 'n_words': 116}