summaryrefslogtreecommitdiff
path: root/ext/intl/tests/msgfmt_parse.phpt
blob: b9ec36374bcbde3a0fb94d99dade173ba268bbe4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
--TEST--
msgfmt_parse() tests
--SKIPIF--
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
--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 {0,number,integer}',
    );
	
	$results = array(
		'en_US' => "4,560 monkeys on 123 trees make 37.073 monkeys per tree",
		'ru_UA' => "4 560 мавп на 123 деревах це 37,073 мавпи на кожному деревi",
		'de' => "4.560 Affen über 123 Bäume um 37,073 Affen pro Baum",
		'en_UK' => "4,560 monkeys on 123 trees make 37.073 monkeys per tree",
		'root' => "4,560 monkeys on 123 trees make 37.073 monkeys per tree",
		'fr' => "C'est 42",
		
	);

	$str_res = '';
	
    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_parse( $fmt, $results[$locale] ) ) . "\n";
		$str_res .= dump( ut_msgfmt_parse_message($locale, $pattern, $results[$locale])) . "\n";
    }
    return $str_res;
}

include_once( 'ut_common.inc' );

// Run the test
ut_run();

?>
--EXPECT--
Locale is: en_US
array (
  0 => 4560,
  1 => 123,
  2 => 37.073,
)
array (
  0 => 4560,
  1 => 123,
  2 => 37.073,
)

Locale is: ru_UA
array (
  0 => 4560,
  1 => 123,
  2 => 37.073,
)
array (
  0 => 4560,
  1 => 123,
  2 => 37.073,
)

Locale is: de
array (
  0 => 4560,
  1 => 123,
  2 => 37.073,
)
array (
  0 => 4560,
  1 => 123,
  2 => 37.073,
)

Locale is: en_UK
array (
  0 => 4560,
  1 => 123,
  2 => 37.073,
)
array (
  0 => 4560,
  1 => 123,
  2 => 37.073,
)

Locale is: root
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'

Locale is: fr
array (
  0 => 42,
)
array (
  0 => 42,
)