diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 94182c4..98b53bb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,11 +2,25 @@ class ApplicationController < ActionController::Base around_action :switch_locale def switch_locale(&action) - locale = I18n.locale_available?(request.headers['Locale']) ? request.headers['Locale'] : I18n.default_locale + locale = extract_locale I18n.with_locale(locale, &action) end def new_session_path(_scope) new_user_session_path end + + def extract_locale + if params[:locale] + I18n.locale_available?(params[:locale]) ? params[:locale] : I18n.default_locale + elsif request.env['HTTP_ACCEPT_LANGUAGE'] + I18n.locale_available?(request.env['HTTP_ACCEPT_LANGUAGE']) ? request.env['HTTP_ACCEPT_LANGUAGE'] : I18n.default_locale + else + I18n.default_locale + end + end + + def default_url_options + { locale: I18n.locale } + end end diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 95a7375..15eb5d8 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -12,6 +12,7 @@ import "bootstrap" import "../stylesheets/application" import "@fortawesome/fontawesome-free/css/all" +import "flag-icon-css/sass/flag-icon" document.addEventListener("turbolinks:load", () => { $('[data-toggle="tooltip"]').tooltip() diff --git a/app/views/layouts/_locales.html.erb b/app/views/layouts/_locales.html.erb new file mode 100644 index 0000000..36beba9 --- /dev/null +++ b/app/views/layouts/_locales.html.erb @@ -0,0 +1,19 @@ + diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index c4564c1..35740f8 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -5,16 +5,19 @@ <% if user_signed_in? %> +