From 62fc7de8a77fdace88dc7e1cb2f407605eb17dce Mon Sep 17 00:00:00 2001 From: Awiteb Date: Tue, 13 Feb 2024 00:16:09 +0300 Subject: [PATCH] improve the `pluralize` macro --- templates/macros/pluralize.html | 34 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/templates/macros/pluralize.html b/templates/macros/pluralize.html index 29fdc620c..e7c3f457b 100644 --- a/templates/macros/pluralize.html +++ b/templates/macros/pluralize.html @@ -1,32 +1,30 @@ {% macro pluralize(language, number) %} {%- set key_prefix = "" -%} + + {# Arabic-specific pluralization rules #} {%- if language == "ar" -%} - {# Arabic-specific pluralization rules #} {%- set modulo = number % 100 -%} - {%- if number > 100 -%} - {%- if modulo == 0 or modulo == 1 or modulo == 2 -%} - {%- set key_prefix = "special_" -%} {# Sixth form for numbers above 100 ending with 0, 1, or 2 #} - {%- endif -%} - {%- elif number == 0 -%} - {%- set key_prefix = "zero_" -%} {# First form for 0 #} - {%- elif number == 1 -%} - {%- set key_prefix = "one_" -%} {# Second form for 1 #} - {%- elif number == 2 -%} - {%- set key_prefix = "two_" -%} {# Third form for 2 #} - {%- elif modulo >= 3 and modulo <= 10 -%} - {%- set key_prefix = "few_" -%} {# Fourth form for numbers ending 3-10 #} - {%- elif modulo >= 11 and modulo <= 99 -%} - {%- set key_prefix = "many_" -%} {# Fifth form for numbers ending 11-99 #} + + {%- if number == 0 -%} + {%- set key_prefix = "zero_" -%} + {%- elif number == 1 %} + {%- set key_prefix = "one_" -%} + {%- elif number == 2 %} + {%- set key_prefix = "two_" -%} + {%- elif number >= 3 and number <= 10 or modulo >= 3 and modulo <= 10 %} + {%- set key_prefix = "few_" -%} {%- else -%} - {%- set key_prefix = "other_" -%} {# Catch-all for any other cases #} + {%- set key_prefix = "many_" -%} {%- endif -%} + + {# Other languages #} {%- else -%} - {# Default pluralization logic for languages other than Arabic #} {%- if number == 1 -%} {%- set key_prefix = "one_" -%} {%- else -%} {%- set key_prefix = "many_" -%} {%- endif -%} {%- endif -%} - {{- key_prefix -}} + + {{-key_prefix-}} {% endmacro %}