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