mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
A11Y: sets the html lang to user's locale when possible (#12007)
This commit is contained in:
parent
d3f03bfb0e
commit
ad7ca46231
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user