From 69a1c4527f59fabd311fbe2c50409b7cb40b4565 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Mon, 27 Feb 2023 17:45:57 -0800 Subject: [PATCH] fix: Fix i18n issues with help center (#6559) --- .../api/v1/portals/articles_controller.rb | 4 +- .../public/api/v1/portals/base_controller.rb | 22 ++++++ .../api/v1/portals/categories_controller.rb | 2 +- .../public/api/v1/portals_controller.rb | 2 +- .../api/v1/portals/_article_count.html.erb | 6 ++ .../api/v1/portals/_category-block.html.erb | 7 +- .../public/api/v1/portals/_footer.html.erb | 2 +- .../public/api/v1/portals/_header.html.erb | 2 +- .../api/v1/portals/articles/index.html.erb | 2 +- .../api/v1/portals/articles/show.html.erb | 4 +- .../categories/_category-block.html.erb | 74 ++++++++++++------- .../api/v1/portals/categories/_hero.html.erb | 2 +- .../api/v1/portals/categories/show.html.erb | 12 ++- config/locales/en.yml | 11 +++ config/locales/fr.yml | 11 +++ 15 files changed, 120 insertions(+), 43 deletions(-) create mode 100644 app/controllers/public/api/v1/portals/base_controller.rb create mode 100644 app/views/public/api/v1/portals/_article_count.html.erb 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 %>
<% if category.articles.published.size == 0 %>
-

No articles here

+

<%= I18n.t('public_portal.common.no_articles') %>

<% else %> <% category.articles.published.take(5).each do |article| %> @@ -47,7 +46,7 @@ class="flex flex-row items-center text-base font-medium text-woot-500 hover:underline mt-4" style="color: <%= portal.color %>" > - View all articles + <%= I18n.t('public_portal.common.view_all_articles') %>

- Made with Chatwoot 💙 + <%= I18n.t('public_portal.footer.made_with') %> Chatwoot 💙

diff --git a/app/views/public/api/v1/portals/_header.html.erb b/app/views/public/api/v1/portals/_header.html.erb index 59065d012..539aa8e64 100644 --- a/app/views/public/api/v1/portals/_header.html.erb +++ b/app/views/public/api/v1/portals/_header.html.erb @@ -8,7 +8,7 @@ <% if @portal.homepage_link %>
diff --git a/app/views/public/api/v1/portals/categories/_category-block.html.erb b/app/views/public/api/v1/portals/categories/_category-block.html.erb index 9d06bb3bd..d99da3503 100644 --- a/app/views/public/api/v1/portals/categories/_category-block.html.erb +++ b/app/views/public/api/v1/portals/categories/_category-block.html.erb @@ -2,41 +2,65 @@

- <%= category.name %> -

<%= category.articles.published.size %> articles + + <%= category.name %> + + + + <%= render 'public/api/v1/portals/article_count', article_count: category.articles.published.size %> +
<% if category.articles.published.size == 0 %> -
-

No articles here

-
+
+

<%= I18n.t('public_portal.common.no_articles') %>

+
<% else %> - <% category.articles.published.take(5).each do |article| %> -
- <%= article.title %> - - - - - -
- <% end %> + <% category.articles.published.take(5).each do |article| %> + + <% end %> <% end %>
- - - View all articles + + <%= I18n.t('public_portal.common.view_all_articles') %> - + + d="M13.267 4.209a.75.75 0 0 0-1.034 1.086l6.251 5.955H3.75a.75.75 0 0 0 0 1.5h14.734l-6.251 5.954a.75.75 0 0 0 1.034 1.087l7.42-7.067a.996.996 0 0 0 .3-.58.758.758 0 0 0-.001-.29.995.995 0 0 0-.3-.578l-7.419-7.067Z" + /> diff --git a/app/views/public/api/v1/portals/categories/_hero.html.erb b/app/views/public/api/v1/portals/categories/_hero.html.erb index 8be6431b1..f9a78c958 100644 --- a/app/views/public/api/v1/portals/categories/_hero.html.erb +++ b/app/views/public/api/v1/portals/categories/_hero.html.erb @@ -2,6 +2,6 @@

<%= portal.header_text %>

-

Search for the articles here or browse the categories below.

+

<%= I18n.t('public_portal.hero.sub_title') %>

diff --git a/app/views/public/api/v1/portals/categories/show.html.erb b/app/views/public/api/v1/portals/categories/show.html.erb index 72b0358e3..ebee41d46 100644 --- a/app/views/public/api/v1/portals/categories/show.html.erb +++ b/app/views/public/api/v1/portals/categories/show.html.erb @@ -11,14 +11,16 @@ class="text-slate-700 text-sm hover:underline leading-8" href="/hc/<%= @portal.slug %>/<%= @category.locale %>" > - Home + <%= I18n.t('public_portal.common.home') %> /

<%= @category.name %>

-
<%= @category.articles.published.size %> articles
+
+ <%= render 'public/api/v1/portals/article_count', article_count: @category.articles.published.size %> +
@@ -27,7 +29,7 @@
<% if @category.articles.published.size == 0 %>
-

No articles here

+

<%= I18n.t('public_portal.common.no_articles') %>

<% else %> <% @category.articles.published.each do |article| %> @@ -37,7 +39,9 @@ >

<%= 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")) %> +

diff --git a/config/locales/en.yml b/config/locales/en.yml index 55ad1dc18..2b2b9ac15 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -186,3 +186,14 @@ en: results_title: Search results hero: sub_title: Search for the articles here or browse the categories below. + common: + home: Home + last_updated_on: Last updated on %{last_updated_on} + view_all_articles: View all articles + article: article + articles: articles + no_articles: There are no articles here + footer: + made_with: Made with + header: + go_to_homepage: Go to the main site diff --git a/config/locales/fr.yml b/config/locales/fr.yml index b578ea860..6acc12c06 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -163,3 +163,14 @@ fr: results_title: Résultats de recherche hero: sub_title: Recherchez les articles ici ou parcourez les catégories ci-dessous. + common: + home: Page d'accueil + last_updated_on: Dernière mise à jour le %{last_updated_on} + view_all_articles: Voir tous les articles + article: article + articles: articles + no_articles: Il n'y a pas d'articles ici + footer: + made_with: Réalisé avec + header: + go_to_homepage: Aller à la page d'accueil