Skip to content

Commit

Permalink
fix: Move integration text to translation file (#1463)
Browse files Browse the repository at this point in the history
- Move integration text to translation file
- Split switch_locale
  • Loading branch information
pranavrajs committed Nov 30, 2020
1 parent d51c5d5 commit 64733ca
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 16 deletions.
2 changes: 2 additions & 0 deletions app/controllers/api/v1/accounts/base_controller.rb
@@ -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

Expand Down
3 changes: 3 additions & 0 deletions app/controllers/api/v1/widget/base_controller.rb
@@ -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

Expand Down
3 changes: 2 additions & 1 deletion app/controllers/application_controller.rb
@@ -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
Expand Down
18 changes: 11 additions & 7 deletions app/controllers/concerns/switch_locale.rb
@@ -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
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/dashboard_controller.rb
@@ -1,7 +1,5 @@
class DashboardController < ActionController::Base
before_action :set_global_config
include SwitchLocale

layout 'vueapp'

def index; end
Expand Down
4 changes: 2 additions & 2 deletions app/models/integrations/app.rb
Expand Up @@ -10,11 +10,11 @@ def id
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
Expand Down
6 changes: 2 additions & 4 deletions config/integration/apps.yml
@@ -1,12 +1,10 @@
slack:
id: slack
name: Slack
logo: slack.png
description: "Slack is a chat tool that brings all your communication together in one place. By integrating Slack, you can get notified of all the new conversations in your account right inside your Slack."
i18n_key: slack
action: https://slack.com/oauth/v2/authorize?scope=commands,chat:write,channels:read,channels:manage,channels:join,groups:write,im:write,mpim:write,users:read,users:read.email,chat:write.customize,channels:history,groups:history,mpim:history,im:history
webhooks:
id: webhook
name: Webhooks
logo: cable.svg
description: Webhook events provide you the realtime information about what's happening in your account. You can make use of the webhooks to communicate the events to your favourite apps like Slack or Github. Click on Configure to set up your webhooks.
i18n_key: slack
action: /webhook
8 changes: 8 additions & 0 deletions config/locales/en.yml
Expand Up @@ -64,3 +64,11 @@ en:
reply:
email_subject: "New messages on this conversation"
transcript_subject: "Conversation Transcript"

integration_apps:
slack:
name: "Slack"
description: "Slack is a chat tool that brings all your communication together in one place. By integrating Slack, you can get notified of all the new conversations in your account right inside your Slack."
webhooks:
name: "Webhooks"
description: "Webhook events provide you the realtime information about what's happening in your account. You can make use of the webhooks to communicate the events to your favourite apps like Slack or Github. Click on Configure to set up your webhooks."
8 changes: 8 additions & 0 deletions config/locales/ml.yml
Expand Up @@ -49,3 +49,11 @@ ml:
reply:
email_subject: "ഈ സംഭാഷണത്തിലെ പുതിയ സന്ദേശങ്ങൾ"
transcript_subject: "സംഭാഷണ ട്രാൻസ്ക്രിപ്റ്റ്"

integration_apps:
slack:
name: "സ്ലാക്ക്"
description: "നിങ്ങളുടെ എല്ലാ ആശയവിനിമയങ്ങളും ഒരിടത്ത് കൊണ്ടുവരുന്ന ഒരു ചാറ്റ് ഉപകരണമാണ് സ്ലാക്ക്. സ്ലാക്ക് സംയോജിപ്പിക്കുന്നതിലൂടെ, നിങ്ങളുടെ അക്കൗണ്ടിലെ എല്ലാ പുതിയ സംഭാഷണങ്ങളെയും നിങ്ങളുടെ സ്ലാക്കിനുള്ളിൽ തന്നെ അറിയാൻ കഴിയും."
webhooks:
name: "വെബ്‌ഹൂക്കുകൾ"
description: "നിങ്ങളുടെ അക്കൗണ്ടിൽ എന്താണ് സംഭവിക്കുന്നതെന്നതിനെക്കുറിച്ചുള്ള തത്സമയ വിവരങ്ങൾ വെബ്‌ഹൂക്ക് ഇവന്റുകൾ നൽകുന്നു. നിങ്ങളുടെ പ്രിയപ്പെട്ട അപ്ലിക്കേഷനുകളിലേക്ക് ഇവന്റുകൾ കൈമാറ്റം ചെയ്യാൻ നിങ്ങൾക്ക് വെബ്‌ഹൂക്കുകൾ ഉപയോഗിക്കാൻ കഴിയും. നിങ്ങളുടെ വെബ്‌ഹൂക്കുകൾ സജ്ജീകരിക്കുന്നതിന് ഇവിടെ ക്ലിക്കുചെയ്യുക."

0 comments on commit 64733ca

Please sign in to comment.