Skip to content

Commit 22336db

Browse files
committed
Fixed bug #70484 selectordinal doesn't work with named parameters
1 parent 72c9324 commit 22336db

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

ext/intl/msgformat/msgformat_helpers.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ static HashTable *umsg_parse_format(MessageFormatter_object *mfo,
264264
type = Formattable::kDouble;
265265
} else if (argType == UMSGPAT_ARG_TYPE_SELECT) {
266266
type = Formattable::kString;
267+
#if U_ICU_VERSION_MAJOR_NUM >= 50
268+
} else if (argType == UMSGPAT_ARG_TYPE_SELECTORDINAL) {
269+
type = Formattable::kDouble;
270+
#endif
267271
} else {
268272
type = Formattable::kString;
269273
}

ext/intl/tests/msgfmt_bug70484.phpt

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
--TEST--
2+
Bug #70484 selectordinal doesn't work with named parameters
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('intl'))
6+
die('skip intl extension not enabled');
7+
if (version_compare(INTL_ICU_VERSION, '5.0') < 0)
8+
die('skip for ICU 5.0+');
9+
--FILE--
10+
<?php
11+
12+
$locale = array("de", "fr", "en", "ru",);
13+
14+
$data = array(42, 42.42, 2147483643, 2147483643.12345, 5);
15+
16+
foreach ($locale as $lc) {
17+
echo "$lc string key\n";
18+
$m = new MessageFormatter($lc, "{n, selectordinal, =5 {five} zero {#-zero} one {#-one} two {#-two} few {#-few} many {#-many} other {#-other}}");
19+
foreach ($data as $i) {
20+
var_dump($m->format(array("n" => $i)));
21+
if ($m->getErrorCode()) {
22+
echo "$lc $i ", $m->getErrorMessage();
23+
}
24+
}
25+
echo "\n";
26+
27+
echo "$lc numeric key\n";
28+
$m = new MessageFormatter($lc, "{0, selectordinal, =5 {five} zero {#-zero} one {#-one} two {#-two} few {#-few} many {#-many} other {#-other}}");
29+
foreach ($data as $i) {
30+
var_dump($m->format(array($i)));
31+
if ($m->getErrorCode()) {
32+
echo "$lc $i ", $m->getErrorMessage();
33+
}
34+
}
35+
echo "\n";
36+
}
37+
38+
?>
39+
==DONE==
40+
--EXPECT--
41+
de string key
42+
string(8) "42-other"
43+
string(11) "42,42-other"
44+
string(19) "2.147.483.643-other"
45+
string(23) "2.147.483.643,123-other"
46+
string(4) "five"
47+
48+
de numeric key
49+
string(8) "42-other"
50+
string(11) "42,42-other"
51+
string(19) "2.147.483.643-other"
52+
string(23) "2.147.483.643,123-other"
53+
string(4) "five"
54+
55+
fr string key
56+
string(8) "42-other"
57+
string(11) "42,42-other"
58+
string(22) "2 147 483 643-other"
59+
string(26) "2 147 483 643,123-other"
60+
string(4) "five"
61+
62+
fr numeric key
63+
string(8) "42-other"
64+
string(11) "42,42-other"
65+
string(22) "2 147 483 643-other"
66+
string(26) "2 147 483 643,123-other"
67+
string(4) "five"
68+
69+
en string key
70+
string(6) "42-two"
71+
string(11) "42.42-other"
72+
string(17) "2,147,483,643-few"
73+
string(23) "2,147,483,643.123-other"
74+
string(4) "five"
75+
76+
en numeric key
77+
string(6) "42-two"
78+
string(11) "42.42-other"
79+
string(17) "2,147,483,643-few"
80+
string(23) "2,147,483,643.123-other"
81+
string(4) "five"
82+
83+
ru string key
84+
string(8) "42-other"
85+
string(11) "42,42-other"
86+
string(22) "2 147 483 643-other"
87+
string(26) "2 147 483 643,123-other"
88+
string(4) "five"
89+
90+
ru numeric key
91+
string(8) "42-other"
92+
string(11) "42,42-other"
93+
string(22) "2 147 483 643-other"
94+
string(26) "2 147 483 643,123-other"
95+
string(4) "five"
96+
97+
==DONE==

0 commit comments

Comments
 (0)