mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 12:08:01 +00:00
We allow users to select locale variants when creating the help center (e.g., pt_BR or en_UK). However, the selected variant may not always be available for translation in the app. In such cases, we need to fall back to either the base language or the default locale. While this fallback logic was implemented for the portal locale, it was missing for article locales. This PR fixes that issue.
64 lines
1.7 KiB
Ruby
64 lines
1.7 KiB
Ruby
class Public::Api::V1::Portals::BaseController < PublicController
|
|
include SwitchLocale
|
|
|
|
before_action :show_plain_layout
|
|
before_action :set_color_scheme
|
|
before_action :set_global_config
|
|
around_action :set_locale
|
|
after_action :allow_iframe_requests
|
|
|
|
private
|
|
|
|
def show_plain_layout
|
|
@is_plain_layout_enabled = params[:show_plain_layout] == 'true'
|
|
end
|
|
|
|
def set_color_scheme
|
|
@theme_from_params = params[:theme] if %w[dark light].include?(params[:theme])
|
|
end
|
|
|
|
def portal
|
|
@portal ||= Portal.find_by!(slug: params[:slug], archived: false)
|
|
end
|
|
|
|
def set_locale(&)
|
|
switch_locale_with_portal(&) if params[:locale].present?
|
|
switch_locale_with_article(&) if params[:article_slug].present?
|
|
|
|
yield
|
|
end
|
|
|
|
def switch_locale_with_portal(&)
|
|
@locale = validate_and_get_locale(params[:locale])
|
|
|
|
I18n.with_locale(@locale, &)
|
|
end
|
|
|
|
def switch_locale_with_article(&)
|
|
article = Article.find_by(slug: params[:article_slug])
|
|
Rails.logger.info "Article: not found for slug: #{params[:article_slug]}"
|
|
render_404 && return if article.blank?
|
|
|
|
article_locale = if article.category.present?
|
|
article.category.locale
|
|
else
|
|
article.portal.default_locale
|
|
end
|
|
@locale = validate_and_get_locale(article_locale)
|
|
I18n.with_locale(@locale, &)
|
|
end
|
|
|
|
def allow_iframe_requests
|
|
response.headers.delete('X-Frame-Options') if @is_plain_layout_enabled
|
|
end
|
|
|
|
def render_404
|
|
portal
|
|
render 'public/api/v1/portals/error/404', status: :not_found
|
|
end
|
|
|
|
def set_global_config
|
|
@global_config = GlobalConfig.get('LOGO_THUMBNAIL', 'BRAND_NAME', 'BRAND_URL')
|
|
end
|
|
end
|