feat(i18n): implement pluralization logic (#277)

Co-authored-by: welpo <welpo@users.noreply.github.com>
This commit is contained in:
Mohammed Alotaibi
2024-02-16 17:41:25 +03:00
committed by GitHub
parent daef40338c
commit c4893d4fdd
22 changed files with 368 additions and 144 deletions

View File

@@ -11,28 +11,21 @@
<ul class="tags">
{%- for term in terms -%}
<li class="tags-item">
{%- set number_of_posts = term.pages | length -%}
{% if config.extra.compact_tags %}
{# Shows the number of posts per tag as a superscript #}
<a href="{{ term.permalink | safe }}"
aria-label="{{ term.name }}
{{ term.pages | length }}
{% if term.pages | length == 1 -%}
{{- macros_translate::translate(key="post", default="post", language_strings=language_strings) -}}
{%- else -%}
{{- macros_translate::translate(key="posts", default="posts", language_strings=language_strings) -}}
{%- endif -%}">
aria-label="{{ term.name }}
{{ term.pages | length }}
{{- macros_translate::translate(key="posts", number=number_of_posts, default="$NUMBER posts", language_strings=language_strings) -}}
">
{{ term.name }}
</a> <sup>{{ term.pages | length }}</sup>
</a> <sup>{{ number_of_posts }}</sup>
{% else %}
<a href="{{ term.permalink | safe }}">
{{ term.name }}</a>
{{ term.pages | length }}{%- if term.pages | length == 1 %}
{# Only one post. Singular. #}
{{- macros_translate::translate(key="post", default="post", language_strings=language_strings) -}}
{% elif term.pages | length > 1 %}
{# More than one post per tag. Plural. #}
{{- macros_translate::translate(key="posts", default="posts", language_strings=language_strings) -}}
{%- endif -%}
{{ term.name }} </a>
<span> </span>
{{- macros_translate::translate(key="posts", number=number_of_posts, default="$NUMBER posts", language_strings=language_strings) -}}
{% endif %}
</li>
{%- endfor -%}