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 $cnt = 0; 105 $res_str = ''; 106 foreach($loc_parts_arr as $key => $value ){ 107 $res_str .= "\n------------"; 108 $res_str .= "\nInput Array name is : loc".(++$cnt) ; 109/* 110 foreach($value as $valKey => $valValue ){ 111 $res_str .= $valKey ."->".$valValue." " ; 112 } 113*/ 114 try { 115 $locale = ut_loc_locale_compose( $value); 116 $res_str .= "\n\nComposed Locale: "; 117 if( $locale){ 118 $res_str .= "$locale"; 119 }else{ 120 $res_str .= "No values found from Locale compose due to the following error:\n"; 121 $res_str .= intl_get_error_message() ; 122 } 123 } catch (ValueError $exception) { 124 echo $exception->getMessage() . "\n"; 125 } 126 } 127 128 $res_str .= "\n------------"; 129 $res_str .= "\n"; 130 return $res_str; 131 132} 133 134include_once( 'ut_common.inc' ); 135ut_run(); 136 137?> 138--EXPECT-- 139Locale::composeLocale(): Argument #1 ($subtags) must contain a "language" key 140locale_compose(): Argument #1 ($subtags) must contain a "language" key 141 142------------ 143Input Array name is : loc1 144 145Composed Locale: sl_Latn_IT 146------------ 147Input Array name is : loc2 148 149Composed Locale: de_DE 150------------ 151Input Array name is : loc3 152 153Composed Locale: hi 154------------ 155Input Array name is : loc4 156 157Composed Locale: zh_Hans_CN 158------------ 159Input Array name is : loc5 160 161Composed Locale: es_Hans_CN 162------------ 163Input Array name is : loc6 164 165Composed Locale: en_Hans_CN_nedis_rozaj 166------------ 167Input Array name is : loc7 168 169Composed Locale: en_lng_ing_Hans_CN_nedis_rozaj 170------------ 171Input Array name is : loc8 172 173Composed Locale: en_lng_ing_Hans_CN_nedis_rozaj_x_prv1_prv2 174------------ 175Input Array name is : loc9 176------------ 177Input Array name is : loc10 178 179Composed Locale: No values found from Locale compose due to the following error: 180locale_compose: parameter array element is not a string: U_ILLEGAL_ARGUMENT_ERROR 181------------ 182Input Array name is : loc11 183 184Composed Locale: No values found from Locale compose due to the following error: 185locale_compose: parameter array element is not a string: U_ILLEGAL_ARGUMENT_ERROR 186------------ 187Input Array name is : loc12 188 189Composed Locale: en_lng_ing_Hans_CN_nedis_rozaj_x_prv1_prv2 190------------ 191