From c9b698743a351e79c9919d10356c66d5e5ffaf85 Mon Sep 17 00:00:00 2001 From: Ahmad Farhat <ahmad.af.farhat@gmail.com> Date: Wed, 11 Oct 2023 15:45:56 -0400 Subject: [PATCH] Fixed issues with default locale (#5452) --- app/controllers/api/v1/sessions_controller.rb | 2 +- app/javascript/contexts/auth/AuthProvider.jsx | 2 +- config/application.rb | 2 ++ sample.env | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/sessions_controller.rb b/app/controllers/api/v1/sessions_controller.rb index e5189613..8c62c232 100644 --- a/app/controllers/api/v1/sessions_controller.rb +++ b/app/controllers/api/v1/sessions_controller.rb @@ -26,7 +26,7 @@ module Api def index return render_data data: current_user, serializer: CurrentUserSerializer, status: :ok if current_user - render_data data: { signed_in: false }, status: :ok + render_data data: { signed_in: false, default_locale: ENV.fetch('DEFAULT_LOCALE') }, status: :ok end # POST /api/v1/sessions diff --git a/app/javascript/contexts/auth/AuthProvider.jsx b/app/javascript/contexts/auth/AuthProvider.jsx index 662804cc..5c896afc 100644 --- a/app/javascript/contexts/auth/AuthProvider.jsx +++ b/app/javascript/contexts/auth/AuthProvider.jsx @@ -38,7 +38,7 @@ export default function AuthProvider({ children }) { provider: currentUser?.provider, avatar: currentUser?.avatar, signed_in: currentUser?.signed_in ?? false, - language: currentUser?.language || window.navigator.language || window.navigator.userLanguage, + language: currentUser?.language || currentUser?.default_locale || window.navigator.language || window.navigator.userLanguage, permissions: currentUser?.permissions, role: currentUser?.role, verified: currentUser?.verified, diff --git a/config/application.rb b/config/application.rb index d37e2120..4cb3322a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -82,5 +82,7 @@ module Greenlight # Fetch 'RELATIVE_URL_ROOT' ENV variable value while removing any trailing slashes. config.relative_url_root = ENV.fetch('RELATIVE_URL_ROOT', nil)&.sub(%r{/*\z}, '') config.relative_url_root = '/' if config.relative_url_root.blank? + + I18n.load_path += Dir[Rails.root.join('config/locales/*.{rb,yml}').to_s] end end diff --git a/sample.env b/sample.env index 405ae57f..7a5f3543 100644 --- a/sample.env +++ b/sample.env @@ -69,7 +69,7 @@ REDIS_URL= #GCS_CLIENT_CERT= # Define the default locale language code (i.e. 'en' for English) from the following list: -# [en, ar, fr, es] +# [en, ar, fr, es, fa_IR] #DEFAULT_LOCALE=en # Set this if you like to deploy Greenlight on a relative root path other than / -- GitLab