|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-11-11 11:17 UTC] nikic@php.net
-Package: intl
+Package: I18N and L10N related
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 17:00:01 2025 UTC |
Description: ------------ In order to select the correct plural form, MessageFormatter needs to pre-format the given argument before choosing the correct plural form, as trailing 0's can affect the plural case. Because of this, the functionality to explicitly set a formatter instance on a parameter needs to be exposed to the PHP User. Otherwise, correct formatting becomes impossible. One can attempt to work around the trailing zero option, by setting the number fromat explicitly in the pattern, however, this then loses all the localized formatting about the groupings. The correct method would be for something like : $nf = new NumberFormatter("hr-HR", NumberFormatter::DECIMAL); $nf->setAttribute(NumberFormatter::FRACTION_DIGITS, 2); $mf = new MessageFormatter("hr-HR", "{num,plural,one{# ONE}two{# TWO}few{# FEW}many{# MANY}other{$ OTHER}}"); // REQUIRED FUNCTIONALITY:: $mf->setFormatter("num", $nf); echo $mf->format(array("num" => 1234.4)); As you can see by the actual results below, the plural section changes by visible trailing zeros, but there is no means to actually properly configure the MessageFormatter to work. Test script: --------------- echo "DEFAULT FORMAT :", MessageFormatter::formatMessage("hr-HR", "{num,plural,one{# ONE}two{# TWO}few{# FEW}many{# MANY}other{{num,number} OTHER}}", array("num" => "1234.40")), PHP_EOL; echo "EXPLICIT FORMAT:", MessageFormatter::formatMessage("hr-HR", "{num,plural,one{# ONE}two{# TWO}few{# FEW}many{# MANY}other{{num,number,0.00} OTHER}}", array("num" => "1234.40")), PHP_EOL; Actual result: -------------- DEFAULT FORMAT :1.234,4 FEW EXPLICIT FORMAT:1234,40 OTHER