File: auto_locale.rb

package info (click to toggle)
ruby-http-accept-language 2.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 140 kB
  • sloc: ruby: 363; makefile: 3
file content (21 lines) | stat: -rw-r--r-- 453 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'active_support/concern'

module HttpAcceptLanguage
  module AutoLocale
    extend ActiveSupport::Concern

    included do
      if respond_to?(:prepend_before_action)
        prepend_before_action :set_locale
      else
        prepend_before_filter :set_locale
      end
    end

    private

    def set_locale
      I18n.locale = http_accept_language.compatible_language_from(I18n.available_locales) || I18n.default_locale
    end
  end
end