Skip to content

Commit

Permalink
pluralize slavic languages
Browse files Browse the repository at this point in the history
  • Loading branch information
welpo committed Feb 14, 2024
1 parent 9f51ef5 commit 3fe4ca5
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion templates/macros/translate.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% macro translate(key, number=-1, language_strings="", default="") %}
{%- set key_prefix = "" -%}
{%- set slavic_plural_languages = ["uk", "be", "bs", "hr", "ru", "sr"] -%}

{%- set key_prefix = "" -%}
{#- `zero_` and `one_` are common cases. We handle "many" (plural) later, after language-specific pluralization -#}
{%- if number == 0 -%}
{%- set key_prefix = "zero_" -%}
Expand All @@ -10,6 +11,7 @@

{#- Pluralization -#}
{%- if number != -1 and key_prefix == "" -%}
{#- Arabic -#}
{%- if lang == "ar" -%}
{%- set modulo = number % 100 -%}
{%- if number == 2 -%}
Expand All @@ -19,6 +21,21 @@
{%- else -%}
{%- set key_prefix = "many_" -%}
{%- endif -%}
{#- Slavic languages like Russian or Ukrainian -#}
{%- elif lang in slavic_plural_languages -%}
{%- set modulo10 = number % 10 -%}
{%- set modulo100 = number % 100 -%}
{%- if modulo10 == 1 and modulo100 != 11 -%}
{%- set key_prefix = "one_" -%}
{%- elif modulo10 >= 2 and modulo10 <= 4 and not modulo100 >= 12 and not modulo100 <= 14 -%}
{%- if modulo100 < 12 or modulo100 > 14 -%}
{%- set key_prefix = "few_" -%}
{%- else -%}
{%- set key_prefix = "many_" -%}
{%- endif -%}
{%- else -%}
{%- set key_prefix = "many_" -%}
{%- endif -%}
{%- else -%}
{#- Default pluralization -#}
{#- Zero and one are already handled -#}
Expand Down

0 comments on commit 3fe4ca5

Please sign in to comment.