diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index ae2f7e02..91cfca6c 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -33,7 +33,9 @@ class AccountsController < ApplicationController Docuseal.refresh_default_url_options! - redirect_to settings_account_path, notice: I18n.t('account_information_has_been_updated') + with_locale do + redirect_to settings_account_path, notice: I18n.t('account_information_has_been_updated') + end rescue ActiveRecord::RecordInvalid render :show, status: :unprocessable_entity end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 970c9d94..a5114318 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base check_authorization unless: :devise_controller? - before_action :set_locale + around_action :with_locale before_action :sign_in_for_demo, if: -> { Docuseal.demo? } before_action :maybe_redirect_to_setup, unless: :signed_in? before_action :authenticate_user!, unless: :devise_controller? @@ -52,18 +52,18 @@ class ApplicationController < ActionController::Base private - def set_locale - I18n.locale = - if Rails.env.development? && params[:locale].present? - params[:locale] - elsif current_user && current_account.locale.present? - current_account.locale.to_sym - else - I18n.default_locale - end + def with_locale(&) + return yield unless current_account + + locale = params[:lang].presence if Rails.env.development? + locale ||= current_account.locale + + I18n.with_locale(locale, &) end def with_browser_locale(&) + return yield if I18n.locale != :'en-US' + locale = params[:lang].presence locale ||= request.env['HTTP_ACCEPT_LANGUAGE'].to_s[BROWSER_LOCALE_REGEXP].to_s diff --git a/app/controllers/setup_controller.rb b/app/controllers/setup_controller.rb index c6a08c58..9b49b1f8 100644 --- a/app/controllers/setup_controller.rb +++ b/app/controllers/setup_controller.rb @@ -56,7 +56,7 @@ class SetupController < ApplicationController def account_params return {} unless params[:account] - params.require(:account).permit(:name, :timezone) + params.require(:account).permit(:name, :timezone, :locale) end def encrypted_config_params diff --git a/app/javascript/form.js b/app/javascript/form.js index eca075ab..6d1eeaa7 100644 --- a/app/javascript/form.js +++ b/app/javascript/form.js @@ -21,6 +21,7 @@ safeRegisterElement('submission-form', class extends HTMLElement { isDemo: this.dataset.isDemo === 'true', attribution: this.dataset.attribution !== 'false', scrollPadding: this.dataset.scrollPadding || '-80px', + language: this.dataset.language, dryRun: this.dataset.dryRun === 'true', expand: ['true', 'false'].includes(this.dataset.expand) ? this.dataset.expand === 'true' : null, withSignatureId: this.dataset.withSignatureId === 'true', diff --git a/app/models/template.rb b/app/models/template.rb index 54d29a43..ec4ecec8 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -46,7 +46,7 @@ class Template < ApplicationRecord attribute :preferences, :string, default: -> { {} } attribute :fields, :string, default: -> { [] } attribute :schema, :string, default: -> { [] } - attribute :submitters, :string, default: -> { [{ name: DEFAULT_SUBMITTER_NAME, uuid: SecureRandom.uuid }] } + attribute :submitters, :string, default: -> { [{ name: I18n.t(:first_party), uuid: SecureRandom.uuid }] } attribute :slug, :string, default: -> { SecureRandom.base58(14) } attribute :source, :string, default: 'native' diff --git a/app/views/accounts/show.html.erb b/app/views/accounts/show.html.erb index e4d6e49f..2ea9a167 100644 --- a/app/views/accounts/show.html.erb +++ b/app/views/accounts/show.html.erb @@ -19,7 +19,7 @@