fix: Fix i18n issues with help center (#6559)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
class Public::Api::V1::Portals::ArticlesController < PublicController
|
||||
class Public::Api::V1::Portals::ArticlesController < Public::Api::V1::Portals::BaseController
|
||||
before_action :ensure_custom_domain_request, only: [:show, :index]
|
||||
before_action :portal
|
||||
before_action :set_category, except: [:index]
|
||||
@@ -34,7 +34,7 @@ class Public::Api::V1::Portals::ArticlesController < PublicController
|
||||
end
|
||||
|
||||
def list_params
|
||||
params.permit(:query)
|
||||
params.permit(:query, :locale)
|
||||
end
|
||||
|
||||
def permitted_params
|
||||
|
||||
22
app/controllers/public/api/v1/portals/base_controller.rb
Normal file
22
app/controllers/public/api/v1/portals/base_controller.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
class Public::Api::V1::Portals::BaseController < PublicController
|
||||
around_action :set_locale
|
||||
|
||||
private
|
||||
|
||||
def set_locale(&)
|
||||
switch_locale_with_portal(&) if params[:locale].present?
|
||||
end
|
||||
|
||||
def switch_locale_with_portal(&)
|
||||
locale_without_variant = params[:locale].split('_')[0]
|
||||
is_locale_available = I18n.available_locales.map(&:to_s).include?(params[:locale])
|
||||
is_locale_variant_available = I18n.available_locales.map(&:to_s).include?(locale_without_variant)
|
||||
if is_locale_available
|
||||
@locale = params[:locale]
|
||||
elsif is_locale_variant_available
|
||||
@locale = locale_without_variant
|
||||
end
|
||||
|
||||
I18n.with_locale(@locale, &)
|
||||
end
|
||||
end
|
||||
@@ -1,4 +1,4 @@
|
||||
class Public::Api::V1::Portals::CategoriesController < PublicController
|
||||
class Public::Api::V1::Portals::CategoriesController < Public::Api::V1::Portals::BaseController
|
||||
before_action :ensure_custom_domain_request, only: [:show, :index]
|
||||
before_action :portal
|
||||
before_action :set_category, only: [:show]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class Public::Api::V1::PortalsController < PublicController
|
||||
class Public::Api::V1::PortalsController < Public::Api::V1::Portals::BaseController
|
||||
before_action :ensure_custom_domain_request, only: [:show]
|
||||
before_action :portal
|
||||
before_action :redirect_to_portal_with_locale, only: [:show]
|
||||
|
||||
Reference in New Issue
Block a user