From 61574103a16b15387bc982e3110b9f6f91871d58 Mon Sep 17 00:00:00 2001 From: welpo Date: Thu, 15 Feb 2024 01:01:22 +0100 Subject: [PATCH] add translate comment for context --- templates/macros/translate.html | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/templates/macros/translate.html b/templates/macros/translate.html index 153dd012..1b138ddb 100644 --- a/templates/macros/translate.html +++ b/templates/macros/translate.html @@ -1,3 +1,20 @@ +{#- Dynamically selects the appropriate translation key based on the provided `number` and `lang` context. +If a `number` is provided, the macro will attempt to pluralize the translation key based on the language's rules. + +Parameters: +- `key`: The base key for the translation string, matching the i18n files. Example: `results` to get `zero_results`, `one_results`, `many_results`, etc. +- `number`: Optional. The numerical value associated with the key. +- `language_strings`: A dictionary containing the translation strings. +- `default`: A default string to use if no translation is found for the key. +- `replace`: Optional. If `true`, the macro will replace the `$NUMBER` placeholder in the translation string with the provided `number`. + +The macro supports special pluralization rules for: +- Arabic (`ar`): Has unique forms for zero, one, two, few, and many. +- Slavic languages: Pluralization depends on the last digit of the number, with exceptions for numbers ending in 11-14. + +NOTE: If the logic for pluralization is modified, it needs to be replicated on the JavaScript search. +Files: static/js/searchElasticlunr.js and its minified version at static/js/searchElasticlunr.min.js +Function name: getPluralizationKey -#} {% macro translate(key, number=-1, language_strings="", default="", replace=true) %} {%- set slavic_plural_languages = ["uk", "be", "bs", "hr", "ru", "sr"] -%} @@ -10,9 +27,6 @@ {%- endif -%} {#- Pluralization -#} - {#- NOTE: If the logic for pluralization is modified, it needs to be replicated on the JavaScript search -#} - {#- Files: static/js/searchElasticlunr.js and its minified version at static/js/searchElasticlunr.min.js -#} - {#- Function name: getPluralizationKey -#} {%- if number != -1 and key_prefix == "" -%} {#- Arabic -#} {%- if lang == "ar" -%}