Browse Source

Use Rack::Locale to detect locale from HTTP headers

pull/79/head
parent
commit
58d8bdd98b
5 changed files with 11 additions and 2 deletions
  1. +2
    -0
      Gemfile
  2. +3
    -0
      Gemfile.lock
  3. +3
    -1
      app/controllers/application_controller.rb
  4. +1
    -1
      app/views/layouts/application.html.erb
  5. +2
    -0
      config.ru

+ 2
- 0
Gemfile View File

@@ -36,6 +36,8 @@ gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'

gem 'rack-contrib'

gem 'open4'
gem 'naught'
gem 'hashie'


+ 3
- 0
Gemfile.lock View File

@@ -214,6 +214,8 @@ GEM
pundit (1.1.0)
activesupport (>= 3.0.0)
rack (2.0.5)
rack-contrib (2.0.1)
rack (~> 2.0)
rack-proxy (0.6.4)
rack
rack-test (1.1.0)
@@ -369,6 +371,7 @@ DEPENDENCIES
pry-rails
puma (~> 3.11)
pundit (~> 1.1)
rack-contrib
rails (~> 5.2.0)
rails-i18n (~> 5.1)
rbnacl (>= 3.2, < 5.0)


+ 3
- 1
app/controllers/application_controller.rb View File

@@ -21,7 +21,9 @@ class ApplicationController < ActionController::Base
end

def set_locale
I18n.locale = current_user.try(:locale) || I18n.default_locale
I18n.locale = current_user.try(:locale) \
|| request.env["rack.locale"].presence \
|| I18n.default_locale
end

def not_found


+ 1
- 1
app/views/layouts/application.html.erb View File

@@ -1,7 +1,7 @@
<% # Copyright (C) 2018 Colin Darie <colin@darie.eu>, 2018 Evolix <info@evolix.fr> %>
<% # License: GNU AGPL-3+ (see full text in LICENSE file) %>
<!DOCTYPE html>
<html>
<html lang="<%= I18n.locale %>">
<head>
<title>Chexpire</title>
<%= csrf_meta_tags %>


+ 2
- 0
config.ru View File

@@ -2,4 +2,6 @@

require_relative "config/environment"

use Rack::Locale

run Rails.application

Loading…
Cancel
Save