gearheads
/
mastodon
Archived
2
0
Fork 0

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

* Fix sr locale being selected over sr-Latn

* Update tests
gh/stable
ThibG 2020-05-11 01:09:21 +02:00 committed by GitHub
parent 4b2d9b8a55
commit 4bcef12bad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 16 deletions

View File

@ -28,18 +28,6 @@ module Localized
end end
def request_locale def request_locale
preferred_locale || compatible_locale http_accept_language.language_region_compatible_from(I18n.available_locales)
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
end end
end end

View File

@ -55,8 +55,8 @@ module Mastodon
:el, :el,
:en, :en,
:eo, :eo,
:'es-AR',
:es, :es,
:'es-AR',
:et, :et,
:eu, :eu,
:fa, :fa,
@ -97,8 +97,8 @@ module Mastodon
:sk, :sk,
:sl, :sl,
:sq, :sq,
:'sr-Latn',
:sr, :sr,
:'sr-Latn',
:sv, :sv,
:ta, :ta,
:te, :te,

View File

@ -16,10 +16,16 @@ describe ApplicationController, type: :controller do
end end
shared_examples 'default locale' 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 it 'sets available and preferred language' do
request.headers['Accept-Language'] = 'ca-ES, fa' request.headers['Accept-Language'] = 'ca-ES, fa'
get 'success' get 'success'
expect(response.body).to eq 'fa' expect(response.body).to eq 'ca'
end end
it 'sets available and compatible language if none of available languages are preferred' do it 'sets available and compatible language if none of available languages are preferred' do