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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rgasler at streamwide dot ro
New email:
PHP Version: OS:

 

 [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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 14:01:30 2024 UTC