diff options
author | ThibG <thib@sitedethib.com> | 2020-05-11 01:09:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-11 01:09:21 +0200 |
commit | 4bcef12bad8f554f3b0fc2fc34b7d4ca4cc567db (patch) | |
tree | 2bf5fb2eb81f92549ae2ca5a925a559260463f3c | |
parent | 4b2d9b8a558190f8ccc51cfe67f5e151f2c3342b (diff) |
Fix sr locale being selected over sr-Latn (#13693)
* Fix sr locale being selected over sr-Latn * Update tests
-rw-r--r-- | app/controllers/concerns/localized.rb | 14 | ||||
-rw-r--r-- | config/application.rb | 4 | ||||
-rw-r--r-- | 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 b43859d9d..d1384ed56 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 d1980cd68..8348649df 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 7635d10e1..a89e24af0 100644 --- a/spec/controllers/concerns/localized_spec.rb +++ b/spec/controllers/concerns/localized_spec.rb @@ -17,9 +17,15 @@ describe ApplicationController, type: :controller do 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 |