1--TEST--
2msgfmt_format() with named subpatterns
3--EXTENSIONS--
4intl
5--FILE--
6<?php
7
8/*
9 * Format a number using misc locales/patterns.
10 */
11
12
13function ut_main()
14{
15
16$pattern=<<<_MSG_
17{gender_of_host, select,
18  female {{num_guests, plural, offset:1
19      =0 {{host} does not give a party.}
20      =1 {{host} invites {guest} to her party.}
21      =2 {{host} invites {guest} and one other person to her party.}
22     other {{host} invites {guest} as one of the # people invited to her party.}}}
23  male   {{num_guests, plural, offset:1
24      =0 {{host} does not give a party.}
25      =1 {{host} invites {guest} to his party.}
26      =2 {{host} invites {guest} and one other person to his party.}
27     other {{host} invites {guest} as one of the # people invited to his party.}}}
28  other {{num_guests, plural, offset:1
29      =0 {{host} does not give a party.}
30      =1 {{host} invites {guest} to their party.}
31      =2 {{host} invites {guest} and one other person to their party.}
32     other {{host} invites {guest} as one of the # people invited to their party.}}}}
33_MSG_;
34
35
36$args = array(
37      array('gender_of_host' => 'female', 'num_guests' => 0, 'host' => 'Alice', 'guest' => 'Bob'),
38      array('gender_of_host' => 'male', 'num_guests' => 1, 'host' => 'Alice', 'guest' => 'Bob'),
39      array('gender_of_host' => 'none', 'num_guests' => 2, 'host' => 'Alice', 'guest' => 'Bob'),
40      array('gender_of_host' => 'female', 'num_guests' => 27, 'host' => 'Alice', 'guest' => 'Bob'),
41);
42
43$str_res = '';
44
45        $fmt = ut_msgfmt_create( 'en_US', $pattern );
46        if(!$fmt) {
47            $str_res .= dump(intl_get_error_message())."\n";
48            return $str_res;
49        }
50        foreach ($args as $arg) {
51            $str_res .= dump( ut_msgfmt_format($fmt, $arg) ). "\n";
52            $str_res .= dump( ut_msgfmt_format_message('en_US', $pattern, $arg) ) . "\n";
53    }
54    return $str_res;
55}
56
57include_once( 'ut_common.inc' );
58
59// Run the test
60ut_run();
61
62?>
63--EXPECT--
64'Alice does not give a party.'
65'Alice does not give a party.'
66'Alice invites Bob to his party.'
67'Alice invites Bob to his party.'
68'Alice invites Bob and one other person to their party.'
69'Alice invites Bob and one other person to their party.'
70'Alice invites Bob as one of the 26 people invited to her party.'
71'Alice invites Bob as one of the 26 people invited to her party.'
72