php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60148 Cannot select rule set when using NumberFormatter with pattern rule based
Submitted: 2011-10-27 14:33 UTC Modified: 2021-11-11 11:16 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: rgasler at streamwide dot ro Assigned:
Status: Open Package: I18N and L10N related
PHP Version: 5.3.8 OS: Ubuntu 11.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
40 - 27 = ?
Subscribe to this entry?

 
 [2011-10-27 14:33 UTC] rgasler at streamwide dot ro
Description:
------------
According to the RuleBasedNumberFormat documentation: http://www.icu-
project.org/apiref/icu4c/classRuleBasedNumberFormat.html#details, a rule pattern 
string can have multiple rule sets.
When calling the format method, it is possible to select the rule set to use. 

But it PHP seems that this is not possible in the current implementation:

NumberFormatter::string format ( number $value [, int $type ] )

Notice that $type is an integer and may take only these possible values:
NumberFormatter::TYPE_DEFAULT
NumberFormatter::TYPE_INT32
NumberFormatter::TYPE_INT64
NumberFormatter::TYPE_DOUBLE
NumberFormatter::TYPE_CURRENCY

For rule set selection to work $type should be a string (the rule set name).


Test script:
---------------
$ruleSet='
%spellout-cardinal:
1:one;
%spellout-ordinal:
1:first;
';

$formatter = new NumberFormatter(null, NumberFormatter::PATTERN_RULEBASED, $ruleSet);

echo $formatter->format(1, 'spellout-ordinal');

Expected result:
----------------
first

Actual result:
--------------
PHP Warning:  NumberFormatter::format() expects parameter 2 to be long, string 
given in /home/raducu/Workspace/Spelling/numbers.php on line 12

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-19 13:02 UTC] clicky at erebot dot net
You're correct in saying it is not possible to select the ruleset when calling format(). But there is a workaround.

You can use the setTextAttribute() method with the NumberFormatter::DEFAULT_RULESET attribute to select the ruleset.
See my comment here for more information: http://php.net/manual/en/numberformatter.create.php#94628 (internally, NumberFormatter::DURATION uses a ruleset).
 [2015-08-18 17:28 UTC] cmb@php.net
-Type: Bug +Type: Feature/Change Request
 [2021-11-11 11:16 UTC] nikic@php.net
-Package: intl +Package: I18N and L10N related
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Nov 28 08:05:53 2022 UTC