From d53cfc0c50401ee17f479ebe329a95050d1e6000 Mon Sep 17 00:00:00 2001 From: Hadi Cheaito <38328371+hadicheaito1@users.noreply.github.com> Date: Tue, 13 Jul 2021 10:04:59 -0400 Subject: [PATCH] Open graph displaying incorrect language bug (#2836) * Open graph displaying incorrect language bug * Cleaning and Fixes --- app/controllers/application_controller.rb | 11 ++++++++--- app/views/layouts/application.html.erb | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 06c922ec..65caa139 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -94,14 +94,18 @@ class ApplicationController < ActionController::Base render :migration_error, status: 500 unless ENV["DB_MIGRATE_FAILED"].blank? end - # Sets the appropriate locale. - def user_locale(user = current_user) - locale = if user && user.language != 'default' + # Determines proper locale to be used by calling user_locale with params based on if room owner exists + def determine_locale(user) + if user && user.language != 'default' user.language else Rails.configuration.default_locale.presence || http_accept_language.language_region_compatible_from(I18n.available_locales) end + end + # Sets the appropriate locale. + def user_locale(user = current_user) + locale = determine_locale(user) begin I18n.locale = locale.tr('-', '_') unless locale.nil? rescue @@ -110,6 +114,7 @@ class ApplicationController < ActionController::Base I18n.locale = "en" end end + helper_method :user_locale # Checks to make sure that the admin has changed his password from the default def check_admin_password diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index bc207516..44aed9c5 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -31,6 +31,7 @@