Xataface
2.0alpha2
Xataface Application Framework
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
Examples
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Groups
Pages
tools
ini2csv.php
Go to the documentation of this file.
1
<?php
13
define(
'_Q'
,
'"'
);
14
define(
'XATAFACEQ'
,
'"'
);
15
function
is_utf8
($str) {
16
if
($str === mb_convert_encoding(mb_convert_encoding($str,
"UTF-32"
,
"UTF-8"
),
"UTF-8"
,
"UTF-32"
)) {
17
return
true
;
18
}
else
{
19
return
false
;
20
}
21
}
22
23
function
encode_if_necessary
($str){
24
if
( !
is_utf8
($str) )
return
utf8_encode($str);
25
else
return
$str;
26
}
27
28
$dicts
= array();
29
$files
= array();
30
$out
=
'translations.csv'
;
31
32
foreach
( $argv as $file ){
33
if
( preg_match(
'/\.csv$/'
, $file) ){
34
$out
= $file;
35
continue
;
36
}
37
if
( !preg_match(
'/\.ini$/'
, $file ) )
continue
;
38
39
$files
[] = $file;
40
$dicts
[$file] = parse_ini_file($file);
41
}
42
43
44
$keys
= array();
45
foreach
(
$dicts
as $dict){
46
foreach
($dict as $key=>$val){
47
if
( !isset(
$keys
[$key]) )
$keys
[$key] = $key;
48
}
49
}
50
51
$fp
= fopen(
$out
,
'wb'
);
52
$fields
=
$files
;
53
array_unshift(
$fields
,
'Key'
);
54
$fields
= array_map(
'encode_if_necessary'
,
$fields
);
55
56
fputcsv(
$fp
,
$fields
);
57
foreach
(
$keys
as $key){
58
$row = array($key);
59
foreach
(
$files
as $file){
60
if
( isset(
$dicts
[$file][$key]) ) $row[] =
$dicts
[$file][$key];
61
else
$row[] =
''
;
62
}
63
$row = array_map(
'encode_if_necessary'
, $row);
64
fputcsv(
$fp
, $row);
65
}
66
fclose(
$fp
);
67
echo
"Translations saved in file $out\n"
;
68
Generated on Fri Mar 22 2013 09:40:34 for Xataface by
1.8.1.2