From 35cadf969dd0161ee62503e242c545f006f7072b Mon Sep 17 00:00:00 2001
From: Cotes Chung <11371340+cotes2020@users.noreply.github.com>
Date: Wed, 8 Jun 2022 05:00:59 +0800
Subject: [PATCH] perf(categories): support singular and plural forms of locale
(#595)
resolves #595
---
_data/locales/en.yml | 8 ++++++--
_layouts/categories.html | 29 +++++++++++++++++++++++++----
2 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/_data/locales/en.yml b/_data/locales/en.yml
index 9e76bd3..14394a6 100644
--- a/_data/locales/en.yml
+++ b/_data/locales/en.yml
@@ -75,5 +75,9 @@ post:
# categories page
categories:
- category_measure: categories
- post_measure: posts
+ category_measure:
+ singular: category
+ plural: categories
+ post_measure:
+ singular: post
+ plural: posts
diff --git a/_layouts/categories.html b/_layouts/categories.html
index 4e9ce77..88c45b0 100644
--- a/_layouts/categories.html
+++ b/_layouts/categories.html
@@ -47,10 +47,24 @@ layout: page
{% if sub_categories_size > 0 %}
{{ sub_categories_size }}
- {{ site.data.locales[lang].categories.category_measure }},
+ {% if sub_categories_size > 1 %}
+ {{ site.data.locales[lang].categories.category_measure.plural
+ | default: site.data.locales[lang].categories.category_measure }}
+ {% else %}
+ {{ site.data.locales[lang].categories.category_measure.singular
+ | default: site.data.locales[lang].categories.category_measure }}
+ {% endif %},
+ {% endif %}
+
+ {{ top_posts_size }}
+
+ {% if top_posts_size > 1 %}
+ {{ site.data.locales[lang].categories.post_measure.plural
+ | default: site.data.locales[lang].categories.post_measure }}
+ {% else %}
+ {{ site.data.locales[lang].categories.post_measure.singular
+ | default: site.data.locales[lang].categories.post_measure }}
{% endif %}
- {{ top_posts_size }}
- {{ site.data.locales[lang].categories.post_measure }}
@@ -83,7 +97,14 @@ layout: page
{% assign posts_size = site.categories[sub_category] | size %}
{{ posts_size }}
- {{ site.data.locales[lang].categories.post_measure }}
+
+ {% if posts_size > 1 %}
+ {{ site.data.locales[lang].categories.post_measure.plural
+ | default: site.data.locales[lang].categories.post_measure }}
+ {% else %}
+ {{ site.data.locales[lang].categories.post_measure.singular
+ | default: site.data.locales[lang].categories.post_measure }}
+ {% endif %}
{% endfor %}