![]() |
Xataface 2.0
Xataface Application Framework
|
00001 <?php 00013 define('_Q','"'); 00014 define('XATAFACEQ', '"'); 00015 function is_utf8($str) { 00016 if ($str === mb_convert_encoding(mb_convert_encoding($str, "UTF-32", "UTF-8"), "UTF-8", "UTF-32")) { 00017 return true; 00018 } else { 00019 return false; 00020 } 00021 } 00022 00023 function encode_if_necessary($str){ 00024 if ( !is_utf8($str) ) return utf8_encode($str); 00025 else return $str; 00026 } 00027 00028 $dicts = array(); 00029 $files = array(); 00030 $out = 'translations.csv'; 00031 00032 foreach ( $argv as $file ){ 00033 if ( preg_match('/\.csv$/', $file) ){ 00034 $out = $file; 00035 continue; 00036 } 00037 if ( !preg_match('/\.ini$/', $file ) )continue; 00038 00039 $files[] = $file; 00040 $dicts[$file] = parse_ini_file($file); 00041 } 00042 00043 00044 $keys = array(); 00045 foreach ($dicts as $dict){ 00046 foreach ($dict as $key=>$val){ 00047 if ( !isset($keys[$key]) ) $keys[$key] = $key; 00048 } 00049 } 00050 00051 $fp = fopen($out, 'wb'); 00052 $fields = $files; 00053 array_unshift($fields, 'Key'); 00054 $fields = array_map('encode_if_necessary', $fields); 00055 00056 fputcsv($fp, $fields); 00057 foreach ($keys as $key){ 00058 $row = array($key); 00059 foreach ($files as $file){ 00060 if ( isset($dicts[$file][$key]) ) $row[] = $dicts[$file][$key]; 00061 else $row[] = ''; 00062 } 00063 $row = array_map('encode_if_necessary', $row); 00064 fputcsv($fp, $row); 00065 } 00066 fclose($fp); 00067 echo "Translations saved in file $out\n"; 00068