feat(i18n): save locale on user
This commit is contained in:
parent
ff7fa4d895
commit
34b1418868
1 changed files with 8 additions and 0 deletions
|
@ -78,6 +78,9 @@ class ApplicationController < ActionController::Base
|
|||
def set_locale(locale)
|
||||
if locale && locale.to_sym.in?(I18n.available_locales)
|
||||
cookies[:locale] = locale
|
||||
if user_signed_in?
|
||||
current_user.update(locale: locale)
|
||||
end
|
||||
locale
|
||||
end
|
||||
end
|
||||
|
@ -322,6 +325,7 @@ class ApplicationController < ActionController::Base
|
|||
def switch_locale(&action)
|
||||
locale = extract_locale_from_query_params ||
|
||||
extract_locale_from_cookie ||
|
||||
extract_locale_from_user ||
|
||||
extract_locale_from_accept_language_header ||
|
||||
I18n.default_locale
|
||||
|
||||
|
@ -332,6 +336,10 @@ class ApplicationController < ActionController::Base
|
|||
set_locale(request.query_parameters[:locale])
|
||||
end
|
||||
|
||||
def extract_locale_from_user
|
||||
current_user&.locale
|
||||
end
|
||||
|
||||
def extract_locale_from_cookie
|
||||
cookies[:locale]
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue