Skip to content

Commit

Permalink
perf(categories): support singular and plural forms of locale (#595)
Browse files Browse the repository at this point in the history
resolves #595
  • Loading branch information
cotes2020 committed Jun 8, 2022
1 parent cc6398c commit 35cadf9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
8 changes: 6 additions & 2 deletions _data/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 25 additions & 4 deletions _layouts/categories.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,24 @@
<span class="text-muted small font-weight-light">
{% 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 }}
</span>
</span>

Expand Down Expand Up @@ -83,7 +97,14 @@
{% assign posts_size = site.categories[sub_category] | size %}
<span class="text-muted small font-weight-light">
{{ 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 %}
</span>
</li>
{% endfor %}
Expand Down

0 comments on commit 35cadf9

Please sign in to comment.