$value) { if (is_array($value)) { if (empty($value)) { unset($input[$key]); } else { $value = remove_emtpy_arrays($value); } } } return $input; } // dirty hack to avoid special handling of the metazone input data copy('data/misc/metaZones.txt', 'data/locales/metaZones.txt'); // since newer icu releases the data is split n multiple files $types = array ("locales", "curr", "zone", "lang", "region"); foreach ($types as $type) { $files = glob("data/".$type."/*.txt"); foreach ($files as $filename) { $locale = substr($filename, 6 + strlen($type)); $locale = substr($locale, 0, -4); // Step 1: convert ICU txt into yml: $icu_data = file_get_contents('data/'.$type.'/'.$locale.'.txt'); $icu_data = sanitize($icu_data); // skip Copyright - file starting with $locale{ $icu_data = preg_replace('/\/\/.*?('.$locale.'\{)/sm','$1', $icu_data); // Remove Duplicated from xxx package $icu_data = preg_replace ('/\{\s*\/\*\*[^\}]*\}/sm','', $icu_data); // this should reference the current locale $icu_data = str_replace('/LOCALE', $locale, $icu_data); // done for BC with old prado files $icu_data = str_replace('%%ALIAS','__ALIAS', $icu_data); // original prado neither uses this, nor imports this correctly. this is a typemarker. php manages this on its own // this enables sensible use of the field if required in future $icu_data = str_replace(':intvector{','{ ', $icu_data); $icu_data = str_replace(':int{','{ ', $icu_data); // hack need to preserve {0} and {1} placeholders from later array conversions: $icu_data = str_replace('{0}','<0>', $icu_data); $icu_data = str_replace('{1}','<1>', $icu_data); // only valid for metazone, but will remove need for manual preprocessing $icu_data = str_replace('metazoneInfo:table(nofallback)', 'metazoneInfo', $icu_data); // Step 2: make yml out of icu format $yml = $icu_data; // create array structure from csv // "R$", // -> // - "R$" $yml = preg_replace('/^(\s*)(.*),\s*$/m','$1- $2',$yml); // create array structure for name elements // PT{"Portugal"} // -> // PT: ["Portugal"] $yml = str_replace('"}','"]', $yml); $yml = str_replace('{"',': ["', $yml); // create yml key-value pairs from { array notation $yml = str_replace('{',':', $yml); $yml = str_replace('}','', $yml); // some example chars are multiline, we will remove them anyway later. // for parsing them lets pretend its a string block $yml = str_replace('ExemplarCharacters:','ExemplarCharacters: |', $yml); // the original CultureInfo class simplified single element arrays into the element alone // now we do this already at data creation time and remove the simplify() calles // this greatly reduces file size and improces runtime performance // PT: ["Portugal"] // -> // PT: "Portugal" $yml = preg_replace('/\[("[^"]*")\]/','$1', $yml); // hack need to preserve {0} and {1} placeholders from later array conversions: $yml = str_replace('<0>','{0}', $yml); $yml = str_replace('<1>','{1}', $yml); // save for manual checks of generated yml file_put_contents('data/'.$type.'/'.$locale.'.yml', $yml); } } // we use the locales directory as input for locales, because it contains all files // 'region' or other may contain less files $files = glob("data/locales/*.yml"); foreach ($files as $filename) { $locale = substr($filename, 6 + strlen('locales')); $locale = substr($locale, 0, -4); // step 3: Load and Merge the YAML files and save serialized $dat_data = array(); foreach ($types as $type) { $array = sfYaml::load('data/'.$type.'/'.$locale.'.yml'); if (is_array($array)) { $type_data = $array[$locale]; if ($type == 'region' && isset($type_data['Countries'])) { foreach ($type_data['Countries'] as $key => $country) { // numeric keys are regions, no countries (why are they in the data files?) if (is_numeric($key)) unset($type_data['Countries'][$key]); } // ZZ is the unknown entry unset($type_data['Countries']['ZZ']); } if ($type == 'curr') { // XXX is unknown and XTS is testing unset($type_data['Currencies']['XTS']); unset($type_data['Currencies']['XXX']); unset($type_data['CurrencyPlurals']['XTS']); unset($type_data['CurrencyPlurals']['XXX']); } $dat_data = array_merge($dat_data, $type_data); } } // those were not in prado and seem not to make any usable sense for us // we remove them to reduce file size unset($dat_data['codePatterns']); unset($dat_data['ExemplarCharacters']); unset($dat_data['AuxExemplarCharacters']); unset($dat_data['CurrencyUnitPatterns']); // possibly remove more, but the data is actually useful // clean any remaining empty arrays $dat_data = remove_emtpy_arrays($dat_data); //save for import into symfony file_put_contents('data/'.$locale.'.dat',serialize($dat_data)); } // postprocess the metaZones.dat into root.dat $metazoneInfo = unserialize(file_get_contents('data/metaZones.dat')); $zones = array(); foreach ($metazoneInfo['metazoneMappings'] as $key => $value) { // only take last valid timezone mapping $validMetazone = array_pop($value); $zones[str_replace(':', '/', $key)] = $validMetazone[0]; } // add to root file $rootData = unserialize(file_get_contents('data/root.dat')); $rootData['TimeZones'] = $zones; file_put_contents('data/root.dat',serialize($rootData)); unlink('data/metaZones.dat');