8000 [#12400] Added tip about ranges in the new ICU message format · symfony/symfony-docs@2baeb1c · GitHub
[go: up one dir, main page]

Skip to content

Commit 2baeb1c

Browse files
committed
[#12400] Added tip about ranges in the new ICU message format
1 parent b3d5de6 commit 2baeb1c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

translation/message_format.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,27 @@ Usage of this string is the same as with variables and select::
267267
}
268268
}
269269
270+
.. sidebar:: Using Ranges in Messages
271+
272+
The pluralization in the legacy Symfony syntax could be used with custom
273+
ranges (e.g. have a different messages for 0-12, 12-40 and 40+). The ICU
274+
message format does not have this feature. Instead, this logic should be
275+
moved to PHP code::
276+
277+
// Instead of
278+
$message = $translator->trans('balance_message', $balance);
279+
// with a message like:
280+
// ]-Inf,0]Oops! I'm down|]0,1000]I still have money|]1000,Inf]I have lots of money
281+
282+
// use three different messages for each range:
283+
if ($balance < 0) {
284+
$message = $translator->trans('no_money_message');
285+
} elseif ($balance < 1000) {
286+
$message = $translator->trans('some_money_message');
287+
} else {
288+
$message = $translator->trans('lots_of_money_message');
289+
}
290+
270291
Additional Placeholder Functions
271292
--------------------------------
272293

0 commit comments

Comments
 (0)
0