-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_csv_from_strings.php
71 lines (57 loc) · 1.7 KB
/
generate_csv_from_strings.php
1
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
if( $argc < 2 ) {
echo "Missing path to MantisHub folder.\n";
exit;
}
$t_projects = [
'AuthHub',
'EventLog',
'Helpdesk',
'ImportUsers',
'Kanban',
'LiveLinks',
'MantisHub',
'Slack',
'Teams',
'TrimAttachments',
];
$t_path = rtrim( realpath( trim( $argv[1] ) ), '/' ) . '/';
foreach( $t_projects as $t_project ) {
$t_english_path = $t_path . 'plugins/' . $t_project . '/lang/strings_english.txt';
$t_folder = './output/' . $t_project . '/en/';
if( !file_exists( $t_folder ) ) {
mkdir( $t_folder, 0777, true );
}
generate_csv_for_file( $t_project, $t_english_path, $t_folder . 'english.csv' );
}
echo "\n";
function generate_csv_for_file( $p_project, $p_strings_file, $p_output_file ) {
echo "Processing '$p_project'...\n";
if( !file_exists( $p_strings_file ) ) {
echo "File '$p_strings_file' not found.\n";
exit;
}
include( $p_strings_file );
$t_vars = get_defined_vars();
$t_strings = [];
foreach( $t_vars as $t_name => $t_value ) {
if( stripos( $t_name, 's_' ) !== 0 && $t_name != 'MANTIS_ERROR' ) {
continue;
}
if( $t_name == 'MANTIS_ERROR' ) {
foreach( $t_value as $t_error_name => $t_error_value ) {
$t_strings['MANTIS_ERROR_' . $t_error_name] = $t_error_value;
}
} else {
$t_string_name = substr( $t_name, 2 );
$t_strings[$t_string_name] = $t_value;
}
}
$t_fp = fopen( $p_output_file, 'w' );
if( !empty( $t_strings ) ) {
foreach ( $t_strings as $t_name => $t_value ) {
fputcsv( $t_fp, [ $t_name, $t_value ] );
}
}
fclose( $t_fp );
}