diff --git a/app/controllers/public/api/v1/portals/articles_controller.rb b/app/controllers/public/api/v1/portals/articles_controller.rb index a2d518d8e..5fccc9ad1 100644 --- a/app/controllers/public/api/v1/portals/articles_controller.rb +++ b/app/controllers/public/api/v1/portals/articles_controller.rb @@ -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 diff --git a/app/controllers/public/api/v1/portals/base_controller.rb b/app/controllers/public/api/v1/portals/base_controller.rb new file mode 100644 index 000000000..35dbc3ff9 --- /dev/null +++ b/app/controllers/public/api/v1/portals/base_controller.rb @@ -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 diff --git a/app/controllers/public/api/v1/portals/categories_controller.rb b/app/controllers/public/api/v1/portals/categories_controller.rb index 6a6ba6377..b1096fbeb 100644 --- a/app/controllers/public/api/v1/portals/categories_controller.rb +++ b/app/controllers/public/api/v1/portals/categories_controller.rb @@ -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] diff --git a/app/controllers/public/api/v1/portals_controller.rb b/app/controllers/public/api/v1/portals_controller.rb index da9b23956..fe51ed161 100644 --- a/app/controllers/public/api/v1/portals_controller.rb +++ b/app/controllers/public/api/v1/portals_controller.rb @@ -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] diff --git a/app/views/public/api/v1/portals/_article_count.html.erb b/app/views/public/api/v1/portals/_article_count.html.erb new file mode 100644 index 000000000..497c52258 --- /dev/null +++ b/app/views/public/api/v1/portals/_article_count.html.erb @@ -0,0 +1,6 @@ +<% if article_count == 0 %> +<% elsif article_count == 1 %> + <%= article_count %> <%= I18n.t('public_portal.common.article') %> +<% else %> + <%= article_count %> <%= I18n.t('public_portal.common.articles') %> +<% end %> diff --git a/app/views/public/api/v1/portals/_category-block.html.erb b/app/views/public/api/v1/portals/_category-block.html.erb index cf8e342a9..a3424d432 100644 --- a/app/views/public/api/v1/portals/_category-block.html.erb +++ b/app/views/public/api/v1/portals/_category-block.html.erb @@ -6,14 +6,13 @@ - <%= category.articles.published.size %> - <%= category.articles.published.size === 1 ? 'article': 'articles' %> + <%= render 'public/api/v1/portals/article_count', article_count: category.articles.published.size %>
No articles here
+<%= I18n.t('public_portal.common.no_articles') %>
No articles here
-<%= I18n.t('public_portal.common.no_articles') %>
+Search for the articles here or browse the categories below.
+<%= I18n.t('public_portal.hero.sub_title') %>
No articles here
+<%= I18n.t('public_portal.common.no_articles') %>
<%= article.title %>
-Last updated on <%= article.updated_at.strftime("%b %d, %Y") %>
++ <%= I18n.t('public_portal.common.last_updated_on', last_updated_on: article.updated_at.strftime("%b %d, %Y")) %> +