1--TEST--
2locale_compose_locale()
3--EXTENSIONS--
4intl
5--FILE--
6<?php
7
8/*
9 * Try parsing different Locales
10 * with Procedural and Object methods.
11 */
12
13function ut_main()
14{
15    $loc_parts_arr1 = array(
16        Locale::LANG_TAG =>'sl' ,
17        Locale::SCRIPT_TAG =>'Latn' ,
18        Locale::REGION_TAG =>'IT'
19    );
20    $loc_parts_arr2 = array(
21        Locale::LANG_TAG =>'de' ,
22        Locale::REGION_TAG =>'DE'
23    );
24    $loc_parts_arr3 = array(
25        Locale::LANG_TAG =>'hi'
26    );
27    $loc_parts_arr4 = array(
28        Locale::LANG_TAG =>'zh' ,
29        Locale::SCRIPT_TAG =>'Hans' ,
30        Locale::REGION_TAG =>'CN'
31    );
32    $loc_parts_arr5 = array(
33        Locale::LANG_TAG =>'es' ,
34        Locale::SCRIPT_TAG =>'Hans' ,
35        Locale::REGION_TAG =>'CN'
36    );
37    $loc_parts_arr6 = array(
38        Locale::LANG_TAG =>'en' ,
39        Locale::SCRIPT_TAG =>'Hans' ,
40        Locale::REGION_TAG =>'CN',
41        Locale::VARIANT_TAG.'14' =>'rozaj' ,
42        'variant1'=>'nedis'
43    );
44    $loc_parts_arr7 = array(
45        Locale::LANG_TAG =>'en' ,
46        Locale::SCRIPT_TAG =>'Hans' ,
47        Locale::REGION_TAG =>'CN',
48        'variant14'=>'rozaj' ,
49        'variant1'=>'nedis' ,
50        'extlang0'=>'lng' ,
51        'extlang1'=>'ing'
52    );
53    $loc_parts_arr8 = array(
54        Locale::LANG_TAG =>'en' ,
55        Locale::SCRIPT_TAG =>'Hans' ,
56        Locale::REGION_TAG =>'CN',
57        'variant14'=>'rozaj' ,
58        'variant1'=>'nedis' ,
59        'extlang0'=>'lng' ,
60        'extlang1'=>'ing',
61        'private7'=>'prv1' ,
62        'private9'=>'prv2'
63    );
64    $loc_parts_arr9 = array(
65        Locale::REGION_TAG =>'DE'
66    );
67    $loc_parts_arr10 = array(
68        Locale::LANG_TAG => 45,
69        Locale::REGION_TAG => false,
70        Locale::SCRIPT_TAG => 15
71    );
72    $loc_parts_arr11 = array(
73        Locale::LANG_TAG =>'de'  ,
74        Locale::REGION_TAG =>'DE',
75        'private0' => 13,
76        'variant1' => array(),
77        'extlang2' => false
78    );
79        $loc_parts_arr12 = array(
80                Locale::LANG_TAG =>'en' ,
81                Locale::SCRIPT_TAG =>'Hans' ,
82                Locale::REGION_TAG =>'CN',
83                Locale::VARIANT_TAG => array('nedis', 'rozaj'),
84        Locale::PRIVATE_TAG => array('prv1', 'prv2'),
85        Locale::EXTLANG_TAG => array('lng', 'ing')
86        );
87
88
89    $loc_parts_arr = array(
90        'loc1' => $loc_parts_arr1	,
91        'loc2' => $loc_parts_arr2	,
92        'loc3' => $loc_parts_arr3	,
93        'loc4' => $loc_parts_arr4	,
94        'loc5' => $loc_parts_arr5	,
95        'loc6' => $loc_parts_arr6	,
96        'loc7' => $loc_parts_arr7	,
97        'loc8' => $loc_parts_arr8	,
98        'loc9' => $loc_parts_arr9	,
99        'loc10' => $loc_parts_arr10	,
100        'loc11' => $loc_parts_arr11	,
101        'loc12' => $loc_parts_arr12
102    );
103
104    error_reporting( E_ERROR );
105
106    $cnt  = 0;
107    $res_str = '';
108    foreach($loc_parts_arr as $key => $value ){
109        $res_str .= "\n------------";
110        $res_str .= "\nInput Array name is : loc".(++$cnt) ;
111/*
112        foreach($value as $valKey => $valValue ){
113            $res_str .=  $valKey ."->".$valValue."  " ;
114        }
115*/
116        try {
117            $locale = ut_loc_locale_compose( $value);
118            $res_str .= "\n\nComposed Locale: ";
119            if( $locale){
120                $res_str .= "$locale";
121            }else{
122                $res_str .= "No values found from Locale compose due to the following error:\n";
123                $res_str .= intl_get_error_message() ;
124            }
125        } catch (ValueError $exception) {
126            echo $exception->getMessage() . "\n";
127        }
128    }
129
130    $res_str .= "\n------------";
131    $res_str .= "\n";
132    return $res_str;
133
134}
135
136include_once( 'ut_common.inc' );
137ut_run();
138
139?>
140--EXPECT--
141Locale::composeLocale(): Argument #1 ($subtags) must contain a "language" key
142locale_compose(): Argument #1 ($subtags) must contain a "language" key
143
144------------
145Input Array name is : loc1
146
147Composed Locale: sl_Latn_IT
148------------
149Input Array name is : loc2
150
151Composed Locale: de_DE
152------------
153Input Array name is : loc3
154
155Composed Locale: hi
156------------
157Input Array name is : loc4
158
159Composed Locale: zh_Hans_CN
160------------
161Input Array name is : loc5
162
163Composed Locale: es_Hans_CN
164------------
165Input Array name is : loc6
166
167Composed Locale: en_Hans_CN_nedis_rozaj
168------------
169Input Array name is : loc7
170
171Composed Locale: en_lng_ing_Hans_CN_nedis_rozaj
172------------
173Input Array name is : loc8
174
175Composed Locale: en_lng_ing_Hans_CN_nedis_rozaj_x_prv1_prv2
176------------
177Input Array name is : loc9
178------------
179Input Array name is : loc10
180
181Composed Locale: No values found from Locale compose due to the following error:
182locale_compose: parameter array element is not a string: U_ILLEGAL_ARGUMENT_ERROR
183------------
184Input Array name is : loc11
185
186Composed Locale: No values found from Locale compose due to the following error:
187locale_compose: parameter array element is not a string: U_ILLEGAL_ARGUMENT_ERROR
188------------
189Input Array name is : loc12
190
191Composed Locale: en_lng_ing_Hans_CN_nedis_rozaj_x_prv1_prv2
192------------
193