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