Browse Source

Fix sr locale being selected over sr-Latn (#13693)

* Fix sr locale being selected over sr-Latn

* Update tests
master
ThibG 4 years ago
committed by GitHub
parent
commit
4bcef12bad
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 16 deletions
  1. +1
    -13
      app/controllers/concerns/localized.rb
  2. +2
    -2
      config/application.rb
  3. +7
    -1
      spec/controllers/concerns/localized_spec.rb

+ 1
- 13
app/controllers/concerns/localized.rb View File

@ -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

+ 2
- 2
config/application.rb View File

@ -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,

+ 7
- 1
spec/controllers/concerns/localized_spec.rb View File

@ -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

Loading…
Cancel
Save