ajout du selecteur de langue
This commit is contained in:
parent
61f49619ba
commit
42153d1d37
6 changed files with 32 additions and 4 deletions
1
app/assets/images/icons/translate-icon.svg
Normal file
1
app/assets/images/icons/translate-icon.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 66 KiB |
|
@ -18,7 +18,8 @@ class ApplicationController < ActionController::Base
|
||||||
before_action :set_active_storage_host
|
before_action :set_active_storage_host
|
||||||
before_action :setup_javascript_settings
|
before_action :setup_javascript_settings
|
||||||
before_action :setup_tracking
|
before_action :setup_tracking
|
||||||
before_action :set_locale
|
|
||||||
|
around_action :switch_locale
|
||||||
|
|
||||||
helper_method :multiple_devise_profile_connect?, :instructeur_signed_in?, :current_instructeur, :current_expert, :expert_signed_in?,
|
helper_method :multiple_devise_profile_connect?, :instructeur_signed_in?, :current_instructeur, :current_expert, :expert_signed_in?,
|
||||||
:administrateur_signed_in?, :current_administrateur, :current_account
|
:administrateur_signed_in?, :current_administrateur, :current_account
|
||||||
|
@ -308,9 +309,15 @@ class ApplicationController < ActionController::Base
|
||||||
current_user&.email
|
current_user&.email
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_locale
|
def switch_locale(&action)
|
||||||
if ENV.fetch('LOCALIZATION_ENABLED', 'false') == 'true'
|
locale = nil
|
||||||
I18n.locale = http_accept_language.compatible_language_from(I18n.available_locales)
|
if cookies[:locale]
|
||||||
|
locale = cookies[:locale]
|
||||||
|
elsif ENV.fetch('LOCALIZATION_ENABLED', 'false') == 'true'
|
||||||
|
locale = http_accept_language.compatible_language_from(I18n.available_locales)
|
||||||
|
else
|
||||||
|
locale = I18n.default_locale
|
||||||
end
|
end
|
||||||
|
I18n.with_locale(locale, &action)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -87,4 +87,9 @@ class RootController < ApplicationController
|
||||||
format.js { render js: helpers.remove_element('#outdated-browser-banner') }
|
format.js { render js: helpers.remove_element('#outdated-browser-banner') }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def save_locale
|
||||||
|
cookies[:locale] = params[:locale]
|
||||||
|
redirect_to request.referer
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,3 +81,6 @@
|
||||||
|
|
||||||
- else
|
- else
|
||||||
= render partial: 'shared/help/help_button'
|
= render partial: 'shared/help/help_button'
|
||||||
|
|
||||||
|
%li
|
||||||
|
= render partial: 'layouts/locale_dropdown'
|
||||||
|
|
11
app/views/layouts/_locale_dropdown.html.haml
Normal file
11
app/views/layouts/_locale_dropdown.html.haml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
.dropdown.locale-dropdown
|
||||||
|
%button.button.dropdown-button.icon-only.header-menu-button{ title: "Translate", 'aria-expanded' => 'false', 'aria-controls' => 'locale_menu' }
|
||||||
|
.hidden Translate
|
||||||
|
= image_tag "icons/translate-icon.svg", alt: 'Translate', 'aria-hidden':'true'
|
||||||
|
%ul.header-menu.dropdown-content#mon_compte_menu
|
||||||
|
%li
|
||||||
|
= link_to save_locale_path(locale: :en), method: :post, class: "menu-item menu-link" do
|
||||||
|
EN - English
|
||||||
|
%li
|
||||||
|
= link_to save_locale_path(locale: :fr), method: :post, class: "menu-item menu-link" do
|
||||||
|
FR - français
|
|
@ -151,6 +151,7 @@ Rails.application.routes.draw do
|
||||||
get "patron" => "root#patron"
|
get "patron" => "root#patron"
|
||||||
get "suivi" => "root#suivi"
|
get "suivi" => "root#suivi"
|
||||||
post "dismiss_outdated_browser" => "root#dismiss_outdated_browser"
|
post "dismiss_outdated_browser" => "root#dismiss_outdated_browser"
|
||||||
|
post "save_locale" => "root#save_locale"
|
||||||
|
|
||||||
get "contact", to: "support#index"
|
get "contact", to: "support#index"
|
||||||
post "contact", to: "support#create"
|
post "contact", to: "support#create"
|
||||||
|
|
Loading…
Reference in a new issue