render consent info in correct locale

pull/7783/head
Markus Kahl 5 years ago
parent fed674f997
commit c635392865
  1. 14
      app/helpers/user_consent_helper.rb
  2. 1
      app/views/account/_user_consent_check.html.erb
  3. 34
      spec/views/account/register.html.erb_spec.rb

@ -38,10 +38,18 @@ module ::UserConsentHelper
Setting.consent_required? && consent_configured? Setting.consent_required? && consent_configured?
end end
def user_consent_instructions(user) ##
language = user.try(:language) || Setting.default_language # Gets consent instructions for the given user.
#
# @param user [User] The user to get instructions for.
# @param locale [String] ISO-639-1 code for the desired locale (e.g. de, en, fr).
# `I18n.locale` is set for each request individually depending
# among other things on the user's Accept-Language headers.
# @return [String] Instructions in the respective language.
def user_consent_instructions(user, locale: I18n.locale)
all = Setting.consent_info all = Setting.consent_info
all.fetch(language) { all.values.first }
all.fetch(locale) { all.values.first }
end end
def consent_configured? def consent_configured?

@ -11,4 +11,3 @@
<%= t('consent.checkbox_label') %> <%= t('consent.checkbox_label') %>
</label> </label>
</section> </section>

@ -114,4 +114,38 @@ describe 'account/register', type: :view do
end end
end end
end end
context "with consent required", with_settings: {
consent_required: true,
consent_info: {
en: "You must consent!",
de: "Du musst zustimmen!"
}
} do
let(:locale) { raise "you have to define the locale" }
before do
I18n.with_locale(locale) do
render
end
end
context "for English (locale: en) users" do
let(:locale) { :en }
it "shows the registration page and consent info in English" do
expect(rendered).to include "new account"
expect(rendered).to include "consent!"
end
end
context "for German (locale: de) users" do
let(:locale) { :de }
it "shows the registration page consent info in German" do
expect(rendered).to include "Neues Konto"
expect(rendered).to include "zustimmen!"
end
end
end
end end

Loading…
Cancel
Save