summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2016-04-11 15:00:58 +0200
committerAnatol Belski <ab@php.net>2016-04-11 15:01:22 +0200
commit28b6f66a77d660412766b6da88d01377cbdd04a1 (patch)
treee1271c9281b5b124de8e020abbb3d5059c5d0cfc
parentf62943edc8f9803b900cc44585beff18cf1361eb (diff)
downloadphp-git-28b6f66a77d660412766b6da88d01377cbdd04a1.tar.gz
Fixed bug #70484 selectordinal doesn't work with named parameters
-rw-r--r--ext/intl/msgformat/msgformat_helpers.cpp4
-rw-r--r--ext/intl/tests/msgfmt_bug70484.phpt97
2 files changed, 101 insertions, 0 deletions
diff --git a/ext/intl/msgformat/msgformat_helpers.cpp b/ext/intl/msgformat/msgformat_helpers.cpp
index ed63105fa7..ce7899edd9 100644
--- a/ext/intl/msgformat/msgformat_helpers.cpp
+++ b/ext/intl/msgformat/msgformat_helpers.cpp
@@ -264,6 +264,10 @@ static HashTable *umsg_parse_format(MessageFormatter_object *mfo,
type = Formattable::kDouble;
} else if (argType == UMSGPAT_ARG_TYPE_SELECT) {
type = Formattable::kString;
+#if U_ICU_VERSION_MAJOR_NUM >= 50
+ } else if (argType == UMSGPAT_ARG_TYPE_SELECTORDINAL) {
+ type = Formattable::kDouble;
+#endif
} else {
type = Formattable::kString;
}
diff --git a/ext/intl/tests/msgfmt_bug70484.phpt b/ext/intl/tests/msgfmt_bug70484.phpt
new file mode 100644
index 0000000000..9d0bdc4ee8
--- /dev/null
+++ b/ext/intl/tests/msgfmt_bug70484.phpt
@@ -0,0 +1,97 @@
+--TEST--
+Bug #70484 selectordinal doesn't work with named parameters
+--SKIPIF--
+<?php
+if (!extension_loaded('intl'))
+ die('skip intl extension not enabled');
+if (version_compare(INTL_ICU_VERSION, '5.0') < 0)
+ die('skip for ICU 5.0+');
+--FILE--
+<?php
+
+$locale = array("de", "fr", "en", "ru",);
+
+$data = array(42, 42.42, 2147483643, 2147483643.12345, 5);
+
+foreach ($locale as $lc) {
+ echo "$lc string key\n";
+ $m = new MessageFormatter($lc, "{n, selectordinal, =5 {five} zero {#-zero} one {#-one} two {#-two} few {#-few} many {#-many} other {#-other}}");
+ foreach ($data as $i) {
+ var_dump($m->format(array("n" => $i)));
+ if ($m->getErrorCode()) {
+ echo "$lc $i ", $m->getErrorMessage();
+ }
+ }
+ echo "\n";
+
+ echo "$lc numeric key\n";
+ $m = new MessageFormatter($lc, "{0, selectordinal, =5 {five} zero {#-zero} one {#-one} two {#-two} few {#-few} many {#-many} other {#-other}}");
+ foreach ($data as $i) {
+ var_dump($m->format(array($i)));
+ if ($m->getErrorCode()) {
+ echo "$lc $i ", $m->getErrorMessage();
+ }
+ }
+ echo "\n";
+}
+
+?>
+==DONE==
+--EXPECT--
+de string key
+string(8) "42-other"
+string(11) "42,42-other"
+string(19) "2.147.483.643-other"
+string(23) "2.147.483.643,123-other"
+string(4) "five"
+
+de numeric key
+string(8) "42-other"
+string(11) "42,42-other"
+string(19) "2.147.483.643-other"
+string(23) "2.147.483.643,123-other"
+string(4) "five"
+
+fr string key
+string(8) "42-other"
+string(11) "42,42-other"
+string(22) "2 147 483 643-other"
+string(26) "2 147 483 643,123-other"
+string(4) "five"
+
+fr numeric key
+string(8) "42-other"
+string(11) "42,42-other"
+string(22) "2 147 483 643-other"
+string(26) "2 147 483 643,123-other"
+string(4) "five"
+
+en string key
+string(6) "42-two"
+string(11) "42.42-other"
+string(17) "2,147,483,643-few"
+string(23) "2,147,483,643.123-other"
+string(4) "five"
+
+en numeric key
+string(6) "42-two"
+string(11) "42.42-other"
+string(17) "2,147,483,643-few"
+string(23) "2,147,483,643.123-other"
+string(4) "five"
+
+ru string key
+string(8) "42-other"
+string(11) "42,42-other"
+string(22) "2 147 483 643-other"
+string(26) "2 147 483 643,123-other"
+string(4) "five"
+
+ru numeric key
+string(8) "42-other"
+string(11) "42,42-other"
+string(22) "2 147 483 643-other"
+string(26) "2 147 483 643,123-other"
+string(4) "five"
+
+==DONE==