diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cc8e01ec..96cd481f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -99,7 +99,14 @@ class ApplicationController < ActionController::Base else http_accept_language.language_region_compatible_from(I18n.available_locales) end - I18n.locale = locale.tr('-', '_') unless locale.nil? + + begin + I18n.locale = locale.tr('-', '_') unless locale.nil? + rescue + # Default to English if there are any issues in language + logger.error("Support: User locale is not supported (#{locale}") + I18n.locale = "en" + end end # Checks to make sure that the admin has changed his password from the default diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index ff05ea6d..49ac8192 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -80,6 +80,20 @@ describe ApplicationController do end end + context "setters" do + it "sets the user locale correctly" do + user = create(:user, language: "ru-RU") + + expect(controller.user_locale(user)).to eql("ru_RU") + end + + it "defaults to English locale if invalid language is set" do + user = create(:user, language: "ru") + + expect(controller.user_locale(user)).to eql("en") + end + end + context "allow_greenlight_accounts" do it "allows if user sign up is turned on" do allow(Rails.configuration).to receive(:loadbalanced_configuration).and_return(false)