fix: Move integration text to translation file (#1463)

- Move integration text to translation file
- Split switch_locale
This commit is contained in:
Pranav Raj S
2020-11-30 16:24:54 +05:30
committed by GitHub
parent d51c5d5768
commit 64733ca3bc
9 changed files with 38 additions and 16 deletions

View File

@@ -1,5 +1,7 @@
class Api::V1::Accounts::BaseController < Api::BaseController
include SwitchLocale
before_action :current_account
around_action :switch_locale_using_account_locale
private

View File

@@ -1,6 +1,9 @@
class Api::V1::Widget::BaseController < ApplicationController
include SwitchLocale
before_action :set_web_widget
before_action :set_contact
around_action :switch_locale_using_account_locale
private

View File

@@ -1,11 +1,12 @@
class ApplicationController < ActionController::Base
include DeviseTokenAuth::Concerns::SetUserByToken
include Pundit
include SwitchLocale
protect_from_forgery with: :null_session
before_action :set_current_user, unless: :devise_controller?
include SwitchLocale
around_action :switch_locale
around_action :handle_with_exception, unless: :devise_controller?
# after_action :verify_authorized

View File

@@ -1,21 +1,25 @@
module SwitchLocale
extend ActiveSupport::Concern
included do
around_action :switch_locale
end
private
def switch_locale(&action)
# priority is for locale set in query string (mostly for widget/from js sdk)
locale ||= locale_from_params
# if locale is not set in param, lets try account
locale ||= locale_from_account(@current_account)
# if locale is not set in account, let's use DEFAULT_LOCALE env variable
locale ||= locale_from_env_variable
# if nothing works we rely on default locale
set_locale(locale, &action)
end
def switch_locale_using_account_locale(&action)
locale = locale_from_account(@current_account)
set_locale(locale, &action)
end
def set_locale(locale, &action)
# if locale is empty, use default_locale
locale ||= I18n.default_locale
# ensure locale won't bleed into other requests
# 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

View File

@@ -1,7 +1,5 @@
class DashboardController < ActionController::Base
before_action :set_global_config
include SwitchLocale
layout 'vueapp'
def index; end

View File

@@ -10,11 +10,11 @@ class Integrations::App
end
def name
params[:name]
I18n.t("integration_apps.#{params[:i18n_key]}.name")
end
def description
params[:description]
I18n.t("integration_apps.#{params[:i18n_key]}.description")
end
def logo