A platform for community discussion. Free, open, simple.
A11Y: sets the html lang to user's locale when possible (#12007)
Joffrey JAFFEUXad7ca462310b
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex 48c910f2f9c..34ebaa2eac3 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -207,7 +207,7 @@ module ApplicationHelperenddef html_lang- SiteSetting.default_locale.sub("_", "-")+ (request ? I18n.locale.to_s : SiteSetting.default_locale).sub("_", "-")end# Creates open graph and twitter card meta datadiff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rbindex f69d73b74a1..18f19b1c4c5 100644--- a/spec/helpers/application_helper_spec.rb+++ b/spec/helpers/application_helper_spec.rb@@ -514,4 +514,23 @@ describe ApplicationHelper doexpect(helper.dark_color_scheme?).to eq(true)endend++ 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+ endend