feat: Ability to set installation-wide default locale (#1433)
* Dashboard locale can be set via env variable * Change account locale based on registration page * Set account locale if available Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
parent
dffc888f9c
commit
30802e0c13
8 changed files with 59 additions and 26 deletions
|
@ -5,7 +5,7 @@ class ApplicationController < ActionController::Base
|
|||
protect_from_forgery with: :null_session
|
||||
|
||||
before_action :set_current_user, unless: :devise_controller?
|
||||
around_action :switch_locale
|
||||
include SwitchLocale
|
||||
around_action :handle_with_exception, unless: :devise_controller?
|
||||
|
||||
# after_action :verify_authorized
|
||||
|
@ -60,28 +60,6 @@ class ApplicationController < ActionController::Base
|
|||
render json: exception.to_hash, status: exception.http_status
|
||||
end
|
||||
|
||||
def locale_from_params
|
||||
I18n.available_locales.map(&:to_s).include?(params[:locale]) ? params[:locale] : nil
|
||||
end
|
||||
|
||||
def locale_from_account(account)
|
||||
return unless account
|
||||
|
||||
I18n.available_locales.map(&:to_s).include?(account.locale) ? account.locale : nil
|
||||
end
|
||||
|
||||
def switch_locale(&action)
|
||||
# priority is for locale set in query string (mostly for widget/from js sdk)
|
||||
locale ||= locale_from_params
|
||||
# if local is not set in param, lets try account
|
||||
locale ||= locale_from_account(@current_account)
|
||||
# if nothing works we rely on default locale
|
||||
locale ||= I18n.default_locale
|
||||
# ensure locale won't bleed into other requests
|
||||
# https://guides.rubyonrails.org/i18n.html#managing-the-locale-across-requests
|
||||
I18n.with_locale(locale, &action)
|
||||
end
|
||||
|
||||
def pundit_user
|
||||
{
|
||||
user: Current.user,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue