Skip to content

Commit

Permalink
Default to EN if language is not recognized (bigbluebutton#805)
Browse files Browse the repository at this point in the history
  • Loading branch information
farhatahmad authored and jfederico committed Sep 20, 2019
1 parent e13e762 commit 6d29422
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ def user_locale(user = current_user)
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
Expand Down
14 changes: 14 additions & 0 deletions spec/controllers/application_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ def user_not_found
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)
Expand Down

0 comments on commit 6d29422

Please sign in to comment.