| 1 |
<?php |
|---|
| 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 |
include_once('sfYaml.php'); |
|---|
| 32 |
|
|---|
| 33 |
function sanitize($string) |
|---|
| 34 |
{ |
|---|
| 35 |
if(substr($string, 0,3) == pack("CCC",0xef,0xbb,0xbf)) |
|---|
| 36 |
{ |
|---|
| 37 |
$string = substr($string, 3); |
|---|
| 38 |
} |
|---|
| 39 |
return str_replace(array("\r\n", "\n", "\r"), "\n", $string); |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
function remove_emtpy_arrays($input) |
|---|
| 44 |
{ |
|---|
| 45 |
foreach ($input as $key => $value) |
|---|
| 46 |
{ |
|---|
| 47 |
if (is_array($value)) |
|---|
| 48 |
{ |
|---|
| 49 |
if (empty($value)) |
|---|
| 50 |
{ |
|---|
| 51 |
unset($input[$key]); |
|---|
| 52 |
} |
|---|
| 53 |
else |
|---|
| 54 |
{ |
|---|
| 55 |
$value = remove_emtpy_arrays($value); |
|---|
| 56 |
} |
|---|
| 57 |
} |
|---|
| 58 |
} |
|---|
| 59 |
return $input; |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
copy('data/misc/metazoneInfo.txt', 'data/locales/metazoneInfo.txt'); |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
$types = array ("locales", "curr", "zone", "lang", "region"); |
|---|
| 67 |
|
|---|
| 68 |
foreach ($types as $type) |
|---|
| 69 |
{ |
|---|
| 70 |
$files = glob("data/".$type."/*.txt"); |
|---|
| 71 |
foreach ($files as $filename) |
|---|
| 72 |
{ |
|---|
| 73 |
$locale = substr($filename, 6 + strlen($type)); |
|---|
| 74 |
$locale = substr($locale, 0, -4); |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
$icu_data = file_get_contents('data/'.$type.'/'.$locale.'.txt'); |
|---|
| 78 |
$icu_data = sanitize($icu_data); |
|---|
| 79 |
|
|---|
| 80 |
$icu_data = preg_replace('/\/\/.*?('.$locale.'\{)/sm','$1', $icu_data); |
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
$icu_data = preg_replace ('/\{\s*\/\*\*[^\}]*\}/sm','', $icu_data); |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
$icu_data = str_replace('/LOCALE', $locale, $icu_data); |
|---|
| 87 |
|
|---|
| 88 |
$icu_data = str_replace('%%ALIAS','__ALIAS', $icu_data); |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
// this enables sensible use of the field if required in future |
|---|
| 92 |
$icu_data = str_replace(':intvector{','{ ', $icu_data); |
|---|
| 93 |
$icu_data = str_replace(':int{','{ ', $icu_data); |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
$icu_data = str_replace('{0}','<0>', $icu_data); |
|---|
| 97 |
$icu_data = str_replace('{1}','<1>', $icu_data); |
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
$icu_data = str_replace('metazoneInfo:table(nofallback)', 'metazoneInfo', $icu_data); |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
$yml = $icu_data; |
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
// "R$", |
|---|
| 107 |
// -> |
|---|
| 108 |
// - "R$" |
|---|
| 109 |
$yml = preg_replace('/^(\s*)(.*),\s*$/m','$1- $2',$yml); |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
// PT{"Portugal"} |
|---|
| 113 |
// -> |
|---|
| 114 |
// PT: ["Portugal"] |
|---|
| 115 |
$yml = str_replace('"}','"]', $yml); |
|---|
| 116 |
$yml = str_replace('{"',': ["', $yml); |
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
$yml = str_replace('{',':', $yml); |
|---|
| 120 |
$yml = str_replace('}','', $yml); |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
// for parsing them lets pretend its a string block |
|---|
| 124 |
$yml = str_replace('ExemplarCharacters:','ExemplarCharacters: |', $yml); |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
// now we do this already at data creation time and remove the simplify() calles |
|---|
| 128 |
// this greatly reduces file size and improces runtime performance |
|---|
| 129 |
// PT: ["Portugal"] |
|---|
| 130 |
// -> |
|---|
| 131 |
// PT: "Portugal" |
|---|
| 132 |
$yml = preg_replace('/\[("[^"]*")\]/','$1', $yml); |
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
$yml = str_replace('<0>','{0}', $yml); |
|---|
| 136 |
$yml = str_replace('<1>','{1}', $yml); |
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
file_put_contents('data/'.$type.'/'.$locale.'.yml', $yml); |
|---|
| 140 |
} |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
$files = glob("data/locales/*.yml"); |
|---|
| 146 |
foreach ($files as $filename) |
|---|
| 147 |
{ |
|---|
| 148 |
$locale = substr($filename, 6 + strlen('locales')); |
|---|
| 149 |
$locale = substr($locale, 0, -4); |
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
$dat_data = array(); |
|---|
| 153 |
foreach ($types as $type) |
|---|
| 154 |
{ |
|---|
| 155 |
$array = sfYaml::load('data/'.$type.'/'.$locale.'.yml'); |
|---|
| 156 |
if (is_array($array)) |
|---|
| 157 |
{ |
|---|
| 158 |
$type_data = $array[$locale]; |
|---|
| 159 |
if ($type == 'region' && isset($type_data['Countries'])) |
|---|
| 160 |
{ |
|---|
| 161 |
foreach ($type_data['Countries'] as $key => $country) |
|---|
| 162 |
{ |
|---|
| 163 |
|
|---|
| 164 |
if (is_numeric($key)) unset($type_data['Countries'][$key]); |
|---|
| 165 |
} |
|---|
| 166 |
|
|---|
| 167 |
unset($type_data['Countries']['ZZ']); |
|---|
| 168 |
} |
|---|
| 169 |
if ($type == 'curr') |
|---|
| 170 |
{ |
|---|
| 171 |
|
|---|
| 172 |
unset($type_data['Currencies']['XTS']); |
|---|
| 173 |
unset($type_data['Currencies']['XXX']); |
|---|
| 174 |
unset($type_data['CurrencyPlurals']['XTS']); |
|---|
| 175 |
unset($type_data['CurrencyPlurals']['XXX']); |
|---|
| 176 |
} |
|---|
| 177 |
$dat_data = array_merge($dat_data, $type_data); |
|---|
| 178 |
} |
|---|
| 179 |
} |
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
// we remove them to reduce file size |
|---|
| 183 |
unset($dat_data['codePatterns']); |
|---|
| 184 |
unset($dat_data['ExemplarCharacters']); |
|---|
| 185 |
unset($dat_data['AuxExemplarCharacters']); |
|---|
| 186 |
unset($dat_data['CurrencyUnitPatterns']); |
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
// clean any remaining empty arrays |
|---|
| 191 |
$dat_data = remove_emtpy_arrays($dat_data); |
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
file_put_contents('data/'.$locale.'.dat',serialize($dat_data)); |
|---|
| 195 |
} |
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
$metazoneInfo = unserialize(file_get_contents('data/metazoneInfo.dat')); |
|---|
| 199 |
$zones = array(); |
|---|
| 200 |
foreach ($metazoneInfo['metazoneMappings'] as $key => $value) |
|---|
| 201 |
{ |
|---|
| 202 |
|
|---|
| 203 |
$validMetazone = array_pop($value); |
|---|
| 204 |
$zones[str_replace(':', '/', $key)] = $validMetazone[0]; |
|---|
| 205 |
} |
|---|
| 206 |
|
|---|
| 207 |
$rootData = unserialize(file_get_contents('data/root.dat')); |
|---|
| 208 |
$rootData['TimeZones'] = $zones; |
|---|
| 209 |
file_put_contents('data/root.dat',serialize($rootData)); |
|---|
| 210 |
unlink('data/metazoneInfo.dat'); |
|---|