diff --git a/translation/message_format.rst b/translation/message_format.rst index 7a60e7ba413..b8f146de878 100644 --- a/translation/message_format.rst +++ b/translation/message_format.rst @@ -267,6 +267,69 @@ Usage of this string is the same as with variables and select:: } } +Ranges +~~~~~~ + +Sometimes, it can be handy to use ranges for a translation. The ``intl`` component provides a way to do this, using the ``choice`` function. + +.. configuration-block:: + + .. code-block:: yaml + + # translations/messages+intl-icu.en.yaml + balance_account: >- + {balance, choice, + -∞ < Oops! I'm down | + 0 < I still have money | + 1000 # I have a lot of money ! + } + + .. code-block:: xml + + + + + + + + balance_account + {balance, choice, -∞ < Oops! I'm down | 0 < I still have money | 1000 # I have a lot of money !} + + + + + + .. code-block:: php + + // translations/messages+intl-icu.en.php + return [ + 'balance_account' => '{balance, choice, + -∞ < Oops! I\'m down | + 0 < I still have money | + 1000 # I have a lot of money! + }', + ]; + +Here are some examples of what this ``choice`` formatter will render:: + + // prints "Oops! I'm down" + echo $translator->trans('balance_account', ['balance' => -10]); + echo $translator->trans('balance_account', ['balance' => 0]); + + // prints "I still have money" + echo $translator->trans('balance_account', ['balance' => 10]); + echo $translator->trans('balance_account', ['balance' => 999]); + + // prints "I have a lot of money!" + echo $translator->trans('balance_account', ['balance' => 1000]); + +This formatter adds some characters used as keyword: + +* Ranges must be separated by a pipe (``|``). +* ``<`` means ``inferior to``. +* ``#`` means ``inferior or equal to``. +* ``∞`` is the infinity symbol (U+221E). It can be prefixed with a minus (``-``). + Additional Placeholder Functions --------------------------------