1--TEST-- 2msgfmt_format() 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 $locales = array( 16 'en_US' => "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree", 17 'ru_UA' => "{0,number,integer} мавп на {1,number,integer} деревах це {2,number} мавпи на кожному деревi", 18 'de' => "{0,number,integer} Affen über {1,number,integer} Bäume um {2,number} Affen pro Baum", 19 'en_UK' => "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree", 20 'root' => '{0,whatever} would not work!', 21 'fr' => "C'est la vie!", 22 ); 23 24 $str_res = ''; 25 $m = 4560; 26 $t = 123; 27 28 foreach( $locales as $locale => $pattern ) 29 { 30 $str_res .= "\nLocale is: $locale\n"; 31 $fmt = ut_msgfmt_create( $locale, $pattern ); 32 if(!$fmt) { 33 $str_res .= dump(intl_get_error_message())."\n"; 34 continue; 35 } 36 $str_res .= dump( ut_msgfmt_format( $fmt, array($m, $t, $m/$t) ) ) . "\n"; 37 $str_res .= dump( ut_msgfmt_format_message($locale, $pattern, array($m, $t, $m/$t))) . "\n"; 38 } 39 return $str_res; 40} 41 42include_once( 'ut_common.inc' ); 43 44// Run the test 45ut_run(); 46 47?> 48--EXPECT-- 49Locale is: en_US 50'4,560 monkeys on 123 trees make 37.073 monkeys per tree' 51'4,560 monkeys on 123 trees make 37.073 monkeys per tree' 52 53Locale is: ru_UA 54'4 560 мавп на 123 деревах це 37,073 мавпи на кожному деревi' 55'4 560 мавп на 123 деревах це 37,073 мавпи на кожному деревi' 56 57Locale is: de 58'4.560 Affen über 123 Bäume um 37,073 Affen pro Baum' 59'4.560 Affen über 123 Bäume um 37,073 Affen pro Baum' 60 61Locale is: en_UK 62'4,560 monkeys on 123 trees make 37.073 monkeys per tree' 63'4,560 monkeys on 123 trees make 37.073 monkeys per tree' 64 65Locale is: root 66'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 67 68Locale is: fr 69'C\'est la vie!' 70'C\'est la vie!' 71