Merge pull request #6440 from betagouv/i18n-selector

i18n: affichage du sélecteur de langues pour les navigateurs non-francophones
This commit is contained in:
lydiasan 2021-10-19 18:17:43 +02:00 committed by GitHub
commit fc891a2b22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View file

@ -72,7 +72,11 @@ class ApplicationController < ActionController::Base
alias_method :pundit_user, :current_account
def localization_enabled?
ENV.fetch('LOCALIZATION_ENABLED', 'false') == 'true' || cookies[:locale].present?
ENV.fetch('LOCALIZATION_ENABLED', 'false') == 'true' || cookies[:locale].present? || !browser_prefers_french?
end
def browser_prefers_french?
http_accept_language.compatible_language_from(I18n.available_locales) == 'fr'
end
def set_locale(locale)

View file

@ -49,6 +49,20 @@ Capybara::Screenshot.register_driver :headless_chrome do |driver, path|
end
RSpec.configure do |config|
# Set the user preferred language before Javascript feature specs.
#
# Features specs without Javascript run in a Rack stack, and respect the Accept-Language value.
# However specs using Javascript are run into a Headless Chrome, which doesn't support setting
# the default Accept-Language value reliably.
# So instead we set the locale cookie explicitly before each Javascript test.
config.before(:each, js: true) do
visit '/' # Webdriver needs visiting a page before setting the cookie
Capybara.current_session.driver.browser.manage.add_cookie(
name: :locale,
value: Rails.application.config.i18n.default_locale
)
end
# Examples tagged with :capybara_ignore_server_errors will allow Capybara
# to continue when an exception in raised by Rails.
# This allows to test for error cases.

View file

@ -34,7 +34,7 @@ describe 'new_administrateur/procedures/show.html.haml', type: :view do
render
end
describe 'archive button is visible', js: true do
describe 'archive button is visible' do
it { expect(rendered).not_to have_css('#publish-procedure-link') }
it { expect(rendered).to have_css('#close-procedure-link') }
end