From 4bcef12bad8f554f3b0fc2fc34b7d4ca4cc567db Mon Sep 17 00:00:00 2001 From: ThibG Date: Mon, 11 May 2020 01:09:21 +0200 Subject: [PATCH] Fix sr locale being selected over sr-Latn (#13693) * Fix sr locale being selected over sr-Latn * Update tests --- app/controllers/concerns/localized.rb | 14 +------------- config/application.rb | 4 ++-- spec/controllers/concerns/localized_spec.rb | 8 +++++++- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/app/controllers/concerns/localized.rb b/app/controllers/concerns/localized.rb index b43859d9d62..d1384ed56ff 100644 --- a/app/controllers/concerns/localized.rb +++ b/app/controllers/concerns/localized.rb @@ -28,18 +28,6 @@ module Localized end def request_locale - preferred_locale || compatible_locale - end - - def preferred_locale - http_accept_language.preferred_language_from(available_locales) - end - - def compatible_locale - http_accept_language.compatible_language_from(available_locales) - end - - def available_locales - I18n.available_locales.reverse + http_accept_language.language_region_compatible_from(I18n.available_locales) end end diff --git a/config/application.rb b/config/application.rb index d1980cd6811..8348649df4c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -55,8 +55,8 @@ module Mastodon :el, :en, :eo, - :'es-AR', :es, + :'es-AR', :et, :eu, :fa, @@ -97,8 +97,8 @@ module Mastodon :sk, :sl, :sq, - :'sr-Latn', :sr, + :'sr-Latn', :sv, :ta, :te, diff --git a/spec/controllers/concerns/localized_spec.rb b/spec/controllers/concerns/localized_spec.rb index 7635d10e19f..a89e24af04b 100644 --- a/spec/controllers/concerns/localized_spec.rb +++ b/spec/controllers/concerns/localized_spec.rb @@ -16,10 +16,16 @@ describe ApplicationController, type: :controller do end shared_examples 'default locale' do + it 'sets available and preferred language' do + request.headers['Accept-Language'] = 'sr-Latn' + get 'success' + expect(response.body).to eq 'sr-Latn' + end + it 'sets available and preferred language' do request.headers['Accept-Language'] = 'ca-ES, fa' get 'success' - expect(response.body).to eq 'fa' + expect(response.body).to eq 'ca' end it 'sets available and compatible language if none of available languages are preferred' do