-
Notifications
You must be signed in to change notification settings - Fork 95
/
languages.php
315 lines (260 loc) · 8.91 KB
/
languages.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?php /*
+------------------------------------------------------------------------------+
| Copyright (c) 1997-2023 The PHP Group |
+------------------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected], so we can mail you a copy immediately. |
+------------------------------------------------------------------------------+
| Authors: André L F S Bacci <ae php.net> |
+------------------------------------------------------------------------------+
| Description: Creates and maintains manual languages checkouts. |
+------------------------------------------------------------------------------+
*/
// dir manual revcheck cloneUrl label
lang( "de" , true , true , "[email protected]:php/doc-de.git" , "German" );
lang( "en" , true , false , "[email protected]:php/doc-en.git" , "English" );
lang( "es" , true , true , "[email protected]:php/doc-es.git" , "Spanish" );
lang( "fr" , true , true , "[email protected]:php/doc-fr.git" , "French" );
lang( "it" , true , true , "[email protected]:php/doc-it.git" , "Italian" );
lang( "ja" , true , true , "[email protected]:php/doc-ja.git" , "Japanese" );
lang( "pl" , false , true , "[email protected]:php/doc-pl.git" , "Polish" );
lang( "pt_BR" , true , true , "[email protected]:php/doc-pt_br.git" , "Brazilian Portuguese" );
lang( "ro" , false , true , "[email protected]:php/doc-ro.git" , "Romanian" );
lang( "ru" , true , true , "[email protected]:php/doc-ru.git" , "Russian" );
lang( "tr" , true , true , "[email protected]:php/doc-tr.git" , "Turkish" );
lang( "uk" , true , true , "[email protected]:php/doc-uk.git" , "Ukrainian" );
lang( "zh" , true , true , "[email protected]:php/doc-zh.git" , "Chinese (Simplified)" );
if ( count( $argv ) == 1 )
print_usage();
else
run();
return;
function print_usage()
{
print <<<USAGE
usage: [--clone] [--undo] [--pull] [--mark] [--quiet]
[--list-cvs] [--list-ssv] [--rev] [--all]
[lang] [lang] ...
Options that operates on local repositories:
--clone Clone a sibling language repo, if not exists
--undo Restore and clean up repositories to a pristine state
--pull Executes git pull
--mark Creates/deletes marking files
--quiet Set this option on git commands
Options that output simple listings:
--list-csv List selected langcodes separated with commas
--list-ssv List selected langcodes separated with spaces
Options that select more languages to operate:
--rev Include languages with revcheck flag
--all Include all languages
--base Include doc-base repo
USAGE;
}
function lang( string $code , bool $manual , bool $revcheck , string $cloneUrl , string $label )
{
$lang = new Lang( $code , $manual , $revcheck , $cloneUrl , $label );
Conf::$knowLangs[ $code ] = $lang;
}
class Conf
{
static array $langs = []; // languages to operate
static array $knowLangs = []; // all declared languages
static bool $clone = false;
static bool $undo = false;
static bool $pull = false;
static bool $mark = false;
static string|null $quiet = null;
static bool $listCsv = false;
static bool $listSsv = false;
}
class Lang
{
function __construct
( public string $code
, public bool $manual
, public bool $revcheck
, public string $cloneUrl
, public string $label
, public string $path = "" )
{
$this->path = realpath( __DIR__ . '/..' ) . "/{$code}";
}
}
function run()
{
global $argv;
array_shift( $argv );
foreach( $argv as $arg )
{
switch( $arg )
{
case "--clone": Conf::$clone = true; break;
case "--undo": Conf::$undo = true; break;
case "--pull": Conf::$pull = true; break;
case "--mark": Conf::$mark = true; break;
case "--quiet": Conf::$quiet = "--quiet"; break;
case "--list-csv": Conf::$listCsv = true; break;
case "--list-ssv": Conf::$listSsv = true; break;
case "--all": langAddAll(); break;
case "--rev": langAddRev(); break;
case "--base": langDocbase(); break;
default: langAdd( $arg ); break;
}
}
// Default: languages with build manual flag
if ( count( Conf::$langs ) == 0 )
foreach( Conf::$knowLangs as $lang )
if ( $lang->manual )
Conf::$langs[ $lang->code ] = $lang;
// Exclusive listing commands
if ( Conf::$listCsv || Conf::$listSsv )
{
$lst = [];
foreach( Conf::$langs as $lang )
$lst[] = $lang->code;
if ( Conf::$listCsv )
print implode( ',' , $lst );
else
print implode( ' ' , $lst );
exit;
}
// Composite commands
echo "Selected languages:";
foreach( Conf::$langs as $lang )
echo ' ' . $lang->code;
echo "\n";
gitAll();
dirMark();
}
function langAdd( string $langCode )
{
foreach( Conf::$knowLangs as $lang )
{
if ( $lang->code == $langCode )
{
Conf::$langs[ $lang->code ] = $lang;
return;
}
}
fprintf( STDERR , "Unknown option or langcode: $langCode\n" );
exit(-1);
}
function langAddAll()
{
foreach( Conf::$knowLangs as $lang )
Conf::$langs[ $lang->code ] = $lang;
}
function langAddRev()
{
foreach( Conf::$knowLangs as $lang )
if ( $lang->manual || $lang->revcheck )
Conf::$langs[ $lang->code ] = $lang;
}
function langDocbase()
{
$code = basename( __DIR__ );
$lang = new Lang( $code , false , false , "" , "" );
Conf::$langs[ $lang->code ] = $lang;
}
function gitAll()
{
foreach( Conf::$langs as $lang )
{
gitClone( $lang );
gitUndo ( $lang );
gitPull ( $lang );
}
}
function gitClone( Lang $lang )
{
if ( Conf::$clone == false )
return;
if ( $lang->cloneUrl == "" )
return;
if ( file_exists( $lang->path ) )
{
echo "clone {$lang->code} (already exists)\n";
return;
}
else
echo "clone {$lang->code}\n";
$cmd = array( 'git' , 'clone' , Conf::$quiet , $lang->cloneUrl , $lang->path );
cmdExecute( $cmd );
}
function gitUndo( Lang $lang )
{
if ( Conf::$undo == false )
return;
if ( ! file_exists( $lang->path ) )
{
echo "undo {$lang->code}: path does not exists, skipping.\n";
return;
}
else
echo "undo {$lang->code}\n";
$cmd = array( 'git' , '-C' , $lang->path , 'restore' , Conf::$quiet , '.' );
cmdExecute( $cmd );
$cmd = array( 'git' , '-C' , $lang->path , 'clean' , Conf::$quiet , '-f' , '-d' );
cmdExecute( $cmd );
$cmd = array( 'git' , '-C' , $lang->path , 'clean' , '--quiet' , '-fdx' );
cmdExecute( $cmd );
}
function gitPull( Lang $lang )
{
if ( Conf::$pull == false )
return;
if ( ! file_exists( $lang->path ) )
{
echo "pull {$lang->code}: path does not exists, skipping.\n";
return;
}
else
echo "pull {$lang->code}\n";
$cmd = array( 'git' , '-C' , $lang->path , 'pull' , Conf::$quiet );
cmdExecute( $cmd );
}
function cmdExecute( array $parts )
{
$escaped = [];
foreach( $parts as $part )
if ( $part != null )
$escaped[] = escapeshellarg( $part );
$cmd = implode( ' ' , $escaped );
$rsc = null;
$ret = passthru( $cmd , $rsc );
if ( $ret === false || $rsc != 0 )
{
echo "\nCommand failed, aborting: $cmd\n\n";
exit(-1);
}
}
function dirMark()
{
if ( Conf::$mark == false )
return;
foreach( Conf::$langs as $lang )
{
$text = $lang->label;
if ( $lang->manual ) // Flags langDir as manual build
{
$path = "{$lang->path}/BUILDMAN";
if ( $lang->manual && ! file_exists( $path ) )
file_put_contents( $path , $text );
if ( ! $lang->manual && file_exists( $path ) )
unlink( $path );
}
if ( $lang->manual ) // Flags langDir as genrevdb.php
{
$path = "{$lang->path}/BUILDREV";
if ( $lang->revcheck && ! file_exists( $path ) )
file_put_contents( $path , $text );
if ( ! $lang->revcheck && file_exists( $path ) )
unlink( $path );
}
}
}