php-src/ext/intl/tests/msgfmt_format.phpt
Nikita Popov 7485978339
Migrate SKIPIF -> EXTENSIONS (#7138)
This is an automated migration of most SKIPIF extension_loaded checks.
2021-06-11 11:57:42 +02:00

71 lines
2.0 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

--TEST--
msgfmt_format()
--EXTENSIONS--
intl
--FILE--
<?php
/*
* Format a number using misc locales/patterns.
*/
function ut_main()
{
$locales = array(
'en_US' => "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree",
'ru_UA' => "{0,number,integer} мавп на {1,number,integer} деревах це {2,number} мавпи на кожному деревi",
'de' => "{0,number,integer} Affen über {1,number,integer} Bäume um {2,number} Affen pro Baum",
'en_UK' => "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree",
'root' => '{0,whatever} would not work!',
'fr' => "C'est la vie!",
);
$str_res = '';
$m = 4560;
$t = 123;
foreach( $locales as $locale => $pattern )
{
$str_res .= "\nLocale is: $locale\n";
$fmt = ut_msgfmt_create( $locale, $pattern );
if(!$fmt) {
$str_res .= dump(intl_get_error_message())."\n";
continue;
}
$str_res .= dump( ut_msgfmt_format( $fmt, array($m, $t, $m/$t) ) ) . "\n";
$str_res .= dump( ut_msgfmt_format_message($locale, $pattern, array($m, $t, $m/$t))) . "\n";
}
return $str_res;
}
include_once( 'ut_common.inc' );
// Run the test
ut_run();
?>
--EXPECT--
Locale is: en_US
'4,560 monkeys on 123 trees make 37.073 monkeys per tree'
'4,560 monkeys on 123 trees make 37.073 monkeys per tree'
Locale is: ru_UA
'4 560 мавп на 123 деревах це 37,073 мавпи на кожному деревi'
'4 560 мавп на 123 деревах це 37,073 мавпи на кожному деревi'
Locale is: de
'4.560 Affen über 123 Bäume um 37,073 Affen pro Baum'
'4.560 Affen über 123 Bäume um 37,073 Affen pro Baum'
Locale is: en_UK
'4,560 monkeys on 123 trees make 37.073 monkeys per tree'
'4,560 monkeys on 123 trees make 37.073 monkeys per tree'
Locale is: root
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
Locale is: fr
'C\'est la vie!'
'C\'est la vie!'