A11Y: sets the html lang to user's locale when possible (#12007)

This commit is contained in:
Joffrey JAFFEUX 2021-02-10 16:12:09 +01:00 committed by GitHub
parent d3f03bfb0e
commit ad7ca46231
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -207,7 +207,7 @@ module ApplicationHelper
end
def html_lang
SiteSetting.default_locale.sub("_", "-")
(request ? I18n.locale.to_s : SiteSetting.default_locale).sub("_", "-")
end
# Creates open graph and twitter card meta data

View File

@ -514,4 +514,23 @@ describe ApplicationHelper do
expect(helper.dark_color_scheme?).to eq(true)
end
end
describe 'html_lang' do
fab!(:user) { Fabricate(:user) }
before do
I18n.locale = :de
SiteSetting.default_locale = :fr
end
it 'returns default locale if no request' do
helper.request = nil
expect(helper.html_lang).to eq(SiteSetting.default_locale)
end
it 'returns current user locale if request' do
helper.request.env[Auth::DefaultCurrentUserProvider::CURRENT_USER_KEY] = user
expect(helper.html_lang).to eq(I18n.locale.to_s)
end
end
end