@@ -267,6 +267,69 @@ Usage of this string is the same as with variables and select::
267267 }
268268 }
269269
270+ Ranges
271+ ~~~~~~
272+
273+ Sometimes, it can be handy to use ranges for a translation. The ``intl `` component provides a way to do this, using the ``choice `` function.
274+
275+ .. configuration-block ::
276+
277+ .. code-block :: yaml
278+
279+ # translations/messages+intl-icu.en.yaml
280+ balance_account : >-
281+ {balance, choice,
282+ -∞ < Oops! I'm down |
283+ 0 < I still have money |
284+ 1000 # I have a lot of money !
285+ }
286+
287+ .. code-block :: xml
288+
289+ <!-- translations/messages+intl-icu.en.xlf -->
290+ <?xml version =" 1.0" ?>
291+ <xliff version =" 1.2" xmlns =" urn:oasis:names:tc:xliff:document:1.2" >
292+ <file source-language =" en" datatype =" plaintext" original =" file.ext" >
293+ <body >
294+ <trans-unit id =" balance_account" >
295+ <source >balance_account</source >
296+ <target >{balance, choice, -∞ < Oops! I'm down | 0 < I still have money | 1000 # I have a lot of money !}</target >
297+ </trans-unit >
298+ </body >
299+ </file >
300+ </xliff >
301+
302+ .. code-block :: php
303+
304+ // translations/messages+intl-icu.en.php
305+ return [
306+ 'balance_account' => '{balance, choice,
307+ -∞ < Oops! I\'m down |
308+ 0 < I still have money |
309+ 1000 # I have a lot of money!
310+ }',
311+ ];
312+
313+ Here are some examples of what this ``choice `` formatter will render::
314+
315+ // prints "Oops! I'm down"
316+ echo $translator->trans('balance_account', ['balance' => -10]);
317+ echo $translator->trans('balance_account', ['balance' => 0]);
318+
319+ // prints "I still have money"
320+ echo $translator->trans('balance_account', ['balance' => 10]);
321+ echo $translator->trans('balance_account', ['balance' => 999]);
322+
323+ // prints "I have a lot of money!"
324+ echo $translator->trans('balance_account', ['balance' => 1000]);
325+
326+ This formatter adds some characters used as keyword:
327+
328+ * Ranges must be separated by a pipe (``| ``).
329+ * ``< `` means ``inferior to ``.
330+ * ``# `` means ``inferior or equal to ``.
331+ * ``∞ `` is the infinity symbol (U+221E). It can be prefixed with a minus (``- ``).
332+
270333Additional Placeholder Functions
271334--------------------------------
272335
0 commit comments