-
Notifications
You must be signed in to change notification settings - Fork 35
/
translationtool.php
694 lines (589 loc) · 19.9 KB
/
translationtool.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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2017 Jakob Sack <nextcloud@jakobsack.de>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
require __DIR__ . '/vendor/autoload.php';
class TranslatableApp {
private string $appPath;
private string $name = '';
private string $fakeAppInfoFile;
private string $fakeVueFile;
private string $fakeLocaleFile;
private array $ignoreFiles = [];
private string $translationsPath;
private TranslationTool $tool;
public function __construct(string $appPath, string $translationsPath, TranslationTool $tool) {
$this->appPath = $appPath;
$this->translationsPath = $translationsPath;
$this->tool = $tool;
$this->fakeAppInfoFile = $this->appPath . '/specialAppInfoFakeDummyForL10nScript.php';
$this->fakeVueFile = $this->appPath . '/specialVueFakeDummyForL10nScript.js';
$this->fakeLocaleFile = $this->appPath . '/specialLocaleFakeDummyForL10nScript.php';
$this->setAppName();
if (file_exists($this->appPath . '/.l10nignore')) {
$lines = explode("\n", file_get_contents($this->appPath . '/.l10nignore'));
foreach ($lines as $line) {
if (!$line) {
continue;
}
if (substr($line, 0, 1) === '#') {
continue;
}
$this->ignoreFiles[] = $line;
}
}
echo "Those files are ignored:\n";
print_r($this->ignoreFiles);
}
public function createOrCheckPotFile(bool $checkFiles = false): void {
$pathToPotFile = $this->translationsPath . '/templates/' . $this->name . '.pot';
// Gather required data
$this->createFakeFileForAppInfo();
$this->createFakeFileForVueFiles();
$this->createFakeFileForLocale();
$translatableFiles = $this->findTranslatableFiles(
['.php', '.js', '.jsx', '.mjs', '.html', '.ts', '.tsx'],
['.min.js']
);
// Let gettext create the pot file
$additionalArguments = ' --add-comments=TRANSLATORS --from-code=UTF-8 --package-version="3.14159" --package-name="Nextcloud" --msgid-bugs-address="translations\@example.com"';
foreach ($translatableFiles as $entry) {
$output = '--output=' . escapeshellarg($pathToPotFile);
$keywords = '';
if (substr($entry, -4) === '.php') {
$keywords = '--keyword=t --keyword=n:1,2';
} else {
$keywords = '--keyword=t:2 --keyword=n:2,3';
}
$language = '--language=';
if (substr($entry, -4) === '.php') {
$language .= 'PHP';
} else {
$language .= 'Javascript';
}
$joinexisting = '';
if (file_exists($pathToPotFile)) {
$joinexisting = '--join-existing';
}
$extractAll = $tmpfname = $skipErrors = '';
if ($checkFiles) {
$extractAll = '--extract-all';
// modify output
$tmpfname = tempnam(sys_get_temp_dir(), 'checkpot');
$output = '--output=' . $tmpfname;
// extract-all generates a recurrent warning
$skipErrors = '2>/dev/null';
}
$xgetCmd = 'xgettext ' . $output . ' ' . $joinexisting . ' ' . $keywords . ' ' . $language . ' ' . escapeshellarg($entry) . ' ' . $additionalArguments . ' ' . $extractAll . ' ' . $skipErrors;
$this->tool->log($xgetCmd);
exec($xgetCmd);
// checking files
if ($checkFiles) {
$this->checkMissingTranslations($entry, $tmpfname);
unlink($tmpfname);
}
}
// Don't forget to remove the temporary file
$this->deleteFakeFileForAppInfo();
$this->deleteFakeFileForVueFiles();
$this->deleteFakeFileForLocale();
}
private function checkMissingTranslations(string $entry, string $tmpfname): void {
$translations = Gettext\Translations::fromPoFile($tmpfname);
$first = true;
foreach($translations as $translation) {
if (preg_match_all('/(^|[^a-zA-Z_]+)(t\([^\)]*\))/', $translation->getOriginal(), $matches)) {
$suspects = [];
foreach($matches[2] as $miss) {
if (preg_match('/["\']'.$this->name.'["\']/', $miss)) {
$suspects[] = $miss;
}
}
if (empty($suspects)) {
continue;
}
if ($first) {
echo '** Warning: Check potentially missing translations sentences: ' . $this->name . ' ' . $entry . PHP_EOL;
$first = false;
}
if ($translation->hasReferences()) {
echo '> Starting at line ' . $translation->getReferences()[0][1] . PHP_EOL;
}
foreach($suspects as $suspect) {
echo ' -> ' . $suspect . PHP_EOL;
}
}
}
}
public function createNextcloudFiles(): void {
foreach ($this->findLanguages() as $language) {
$poFile = $this->translationsPath . '/' . $language . '/' . $this->name . '.po';
$translations = Gettext\Translations::fromPoFile($poFile);
$strings = [];
$plurals = $translations->getHeader('Plural-Forms');
foreach ($translations as $translation) {
if (!$translation->hasTranslation()) {
// Skip if we have no translation (for the base form)
continue;
}
if ($translation->hasPlural()) {
$identifier = $this->escape('_' . $translation->getOriginal() . '_::_' . $translation->getPlural() . '_');
$variants = [$this->escape($translation->getTranslation())];
foreach ($translation->getPluralTranslations() as $plural) {
if ($plural === '') {
// We skip the complete string if not all plural forms exist
continue 2;
}
$variants[] = $this->escape($plural);
}
$strings[] = $identifier . ' : [' . join(',', $variants) . ']';
} else {
$strings[] = $this->escape($translation->getOriginal()) . ' : ' . $this->escape($translation->getTranslation());
}
}
// Nothing translated :-( skip this file
if (count($strings) === 0) {
continue;
}
$this->writeJsFile($language, $plurals, $strings);
$this->writeJsonFile($language, $plurals, $strings);
}
}
private function writeJsFile(string $language, string $plurals, array $strings): void {
$outfile = fopen($this->appPath . '/l10n/' . $language . '.js', 'w');
fwrite($outfile, 'OC.L10N.register(' . PHP_EOL);
fwrite($outfile, ' "' . $this->name . '",' . PHP_EOL);
fwrite($outfile, ' {' . PHP_EOL);
fwrite($outfile, ' ');
fwrite($outfile, join(',' . PHP_EOL . ' ', $strings));
fwrite($outfile, PHP_EOL . '},' . PHP_EOL);
fwrite($outfile, $this->escape($plurals) . ');' . PHP_EOL);
fclose($outfile);
}
private function writeJsonFile(string $language, string $plurals, array $strings): void {
$outfile = fopen($this->appPath . '/l10n/' . $language . '.json', 'w');
fwrite($outfile, '{ "translations": {' . PHP_EOL);
fwrite($outfile, ' ');
fwrite($outfile, join(',' . PHP_EOL . ' ', $strings));
fwrite($outfile, PHP_EOL . '},"pluralForm" :' . $this->escape($plurals) . PHP_EOL . '}');
fclose($outfile);
}
private function escape(string $string): string {
return Gettext\Generators\Po::convertString($string);
}
private function hasExtension(string $fileName, string $extensions): bool {
foreach ($extensions as $ext) {
if (substr($fileName, -strlen($ext)) === $ext) {
return true;
}
}
return false;
}
private function findTranslatableFiles(array $extensions, array $ignoredExtensions = [], string $path = ''): array {
$realPath = $path === '' ? $this->appPath : $this->appPath . '/' . $path;
$translatable = [];
$directoryectoryContent = scandir($realPath);
foreach ($directoryectoryContent as $entry) {
if ($entry[0] === '.') {
continue;
}
$newPath = $path === '' ? $entry : $path . '/' . $entry;
$newRealPath = $this->appPath . '/' . $newPath;
if (in_array($newPath, $this->ignoreFiles)) {
continue;
}
foreach ($this->ignoreFiles as $ignoredFile) {
if (strpos($newPath, $ignoredFile) === 0) {
continue 2;
}
}
if (is_dir($newRealPath) && $entry !== 'l10n' && $entry !== 'node_modules') {
$translatable = array_merge($translatable, $this->findTranslatableFiles($extensions, $ignoredExtensions, $newPath));
}
if (is_file($newRealPath)) {
if ($this->hasExtension($entry, $extensions)
&& !$this->hasExtension($entry, $ignoredExtensions)) {
$translatable[] = $newRealPath;
}
}
}
return $translatable;
}
private function findLanguages(): array {
$languages = [];
$directoryContent = scandir($this->translationsPath);
foreach ($directoryContent as $entry) {
if ($entry[0] === '.' || $entry === 'templates' || !is_dir($this->translationsPath . '/' . $entry)) {
continue;
}
if (is_file($this->translationsPath . '/' . $entry . '/' . $this->name . '.po')) {
$languages[] = $entry;
}
}
return $languages;
}
private function createFakeFileForAppInfo() {
$entryName = $this->appPath . '/appinfo/info.xml';
if (!file_exists($entryName)) {
return false;
}
$strings = [];
$xml = simplexml_load_string(file_get_contents($entryName));
if ($xml->name) {
$strings[] = $xml->name->__toString();
}
if ($xml->navigations) {
foreach ($xml->navigations as $navigation) {
$name = $navigation->navigation->name->__toString();
if (!in_array($name, $strings)) {
$strings[] = $name;
}
}
}
if ($xml->name) {
if ($xml->name->count() > 1) {
foreach ($xml->name as $name) {
if ((string)$name->attributes()->lang === 'en') {
$name = $name->__toString();
if (!in_array($name, $strings)) {
$strings[] = $name;
}
}
}
} else {
$name = $xml->name->__toString();
if (!in_array($name, $strings)) {
$strings[] = $name;
}
}
}
if ($xml->summary) {
if ($xml->summary->count() > 1) {
foreach ($xml->summary as $summary) {
if ((string)$summary->attributes()->lang === 'en') {
$name = $summary->__toString();
if (!in_array($name, $strings)) {
$strings[] = $name;
}
}
}
} else {
$name = $xml->summary->__toString();
if (!in_array($name, $strings)) {
$strings[] = $name;
}
}
}
if ($xml->description) {
if ($xml->description->count() > 1) {
foreach ($xml->description as $description) {
if ((string)$description->attributes()->lang === 'en') {
$name = $description->__toString();
if (!in_array($name, $strings)) {
$strings[] = trim($name);
}
}
}
} else {
$name = $xml->description->__toString();
if (!in_array($name, $strings)) {
$strings[] = trim($name);
}
}
}
$content = '<?php' . PHP_EOL;
foreach ($strings as $string) {
$content .= '$l->t(' . $this->escape($string) . ');' . PHP_EOL;
}
file_put_contents($this->fakeAppInfoFile, $content);
}
private function createFakeFileForVueFiles(): void {
$fakeFileContent = '';
foreach ($this->findTranslatableFiles(['.vue']) as $vueFile) {
$vueSource = file_get_contents($vueFile);
if ($vueSource === false) {
echo 'Warning: could not read ' . $vueFile . PHP_EOL;
continue;
}
// t
preg_match_all("/\Wt\s*\(\s*'?([\w.]+)'?,\s*'(.+)'/", $vueSource, $singleQuoteMatches);
preg_match_all("/\Wt\s*\(\s*\"?([\w.]+)\"?,\s*\"(.+)\"/", $vueSource, $doubleQuoteMatches);
preg_match_all("/\Wt\s*\(\s*\'?([\w.]+)\'?\s*,\s*\`(.+)\`\s*\)/msU", $vueSource, $templateQuoteMatches);
$matches0 = array_merge($singleQuoteMatches[0], $doubleQuoteMatches[0], $templateQuoteMatches[0]);
$matches2 = array_merge($singleQuoteMatches[2], $doubleQuoteMatches[2], $templateQuoteMatches[2]);
foreach (array_keys($matches2) as $k) {
$match = $matches2[$k];
$fakeFileContent .= $this->getTranslatorHintWithVueSource($vueFile, $vueSource, $matches0[$k]);
$fakeFileContent .= "t('" . $this->name . "', '" . preg_replace('/\s+/', ' ', $match) . "');" . PHP_EOL;
}
// n
preg_match_all("/\Wn\s*\(\s*'?([\w.]+)'?,\s*'(.+)'\s*,\s*'(.+)'\s*(.+)/", $vueSource, $singleQuoteMatches);
preg_match_all("/\Wn\s*\(\s*\"?([\w.]+)\"?,\s*\"(.+)\"\s*,\s*\"(.+)\"\s*(.+)/", $vueSource, $doubleQuoteMatches);
preg_match_all("/\Wn\s*\(\s*\'?([\w.]+)\'?\s*,\s*\`(.+)\`\s*,\s*\`(.+)\`\s*\)/msU", $vueSource, $templateQuoteMatches);
$matches0 = array_merge($singleQuoteMatches[0], $doubleQuoteMatches[0], $templateQuoteMatches[0]);
$matches2 = array_merge($singleQuoteMatches[2], $doubleQuoteMatches[2], $templateQuoteMatches[2]);
$matches3 = array_merge($singleQuoteMatches[3], $doubleQuoteMatches[3], $templateQuoteMatches[3]);
foreach (array_keys($matches2) as $k) {
$match2 = $matches2[$k];
$match3 = $matches3[$k];
$fakeFileContent .= $this->getTranslatorHintWithVueSource($vueFile, $vueSource, $matches0[$k]);
$fakeFileContent .= "n('" . $this->name . "', '" . preg_replace('/\s+/', ' ', $match2) . "', '" . preg_replace('/\s+/', ' ', $match3) . "');" . PHP_EOL;
}
}
file_put_contents($this->fakeVueFile, $fakeFileContent);
}
private function getTranslatorHintWithVueSource(string $vueFile, string $content, string $translation): string {
$relativeVuePath = substr($vueFile, strpos($vueFile, $this->name . '/src/') + strlen($this->name . '/'));
$position = strpos($content, $translation);
$contentBefore = substr($content, 0, $position);
$contentAfter = substr($content, $position);
$lineNumber = substr_count($contentBefore, "\n") + 1;
$linesBefore = explode("\n", $contentBefore);
$linesAfter = explode("\n", $contentAfter);
$previousLine = $linesBefore[$lineNumber - 2];
$currentLine = $linesAfter[0];
// If we have a translation hint in the current line, we use it
// This prevents mismatching hints if we have two translations
// over consecutive lines
// Like https://github.com/nextcloud/forms/blob/5c905b36b1ce3ca1848175d39d813581732e159d/src/views/Results.vue#L261-L263
$searchComment = strpos($currentLine, 'TRANSLATORS') !== false
? $currentLine
: $previousLine;
// We try to find a comment with the translators hint
// <!-- TRANSLATORS: This is a comment -->
// <!-- TRANSLATORS : This is a comment -->
// <!-- TRANSLATORS This is a comment -->
// t('forms', 'Save to home') // TRANSLATORS: Export the file to the home path
$re = '/TRANSLATORS[: ]*(.*)/m';
preg_match_all($re, $searchComment, $matches, PREG_SET_ORDER, 0);
// If we have a comment, we use it
if (count($matches) > 0 && count($matches[0]) > 1) {
// Remove double spaces
$comment = str_replace(' ', ' ', $matches[0][1]);
// Remove leading and trailing spaces
$comment = trim($comment);
// Remove newlines
$comment = str_replace("\n", '', $comment);
// Remove html end comment
$comment = str_replace('-->', '', $comment);
return str_replace(' ', ' ', '// TRANSLATORS ' . $comment . " ($relativeVuePath:$lineNumber)" . PHP_EOL);
}
return '// TRANSLATORS ' . $relativeVuePath . ':' . $lineNumber . PHP_EOL;
}
private function deleteFakeFileForAppInfo(): void {
if (is_file($this->fakeAppInfoFile)) {
unlink($this->fakeAppInfoFile);
}
}
private function deleteFakeFileForVueFiles(): void {
if (is_file($this->fakeVueFile)) {
unlink($this->fakeVueFile);
}
}
private function setAppName(): void {
$xmlFile = $this->appPath . '/appinfo/info.xml';
$this->name = basename($this->appPath);
if (!file_exists($xmlFile)) {
return;
}
$xml = simplexml_load_string(file_get_contents($xmlFile));
if ($xml->name) {
$this->name = $xml->id->__toString();
}
}
private function createFakeFileForLocale() {
if ($this->name !== 'settings') {
return false;
}
$entryName = $this->appPath . '/../resources/locales.json';
if (!file_exists($entryName)) {
return false;
}
$strings = [];
$locales = json_decode(file_get_contents($entryName), true);
foreach ($locales as $locale) {
$strings[] = $locale['name'];
}
$content = '<?php' . PHP_EOL;
foreach ($strings as $string) {
$content .= '$l->t(' . $this->escape($string) . ');' . PHP_EOL;
}
file_put_contents($this->fakeLocaleFile, $content);
}
private function deleteFakeFileForLocale(): void {
if (is_file($this->fakeLocaleFile)) {
unlink($this->fakeLocaleFile);
}
}
}
class TranslationTool {
private string $translationPath;
private array $appPaths;
private int $verbose = 0;
public function __construct() {
$this->translationPath = getcwd() . '/translationfiles';
$this->appPaths = [];
if (!is_dir($this->translationPath)) {
mkdir($this->translationPath);
}
}
public function setVerbose(int $verbose): void {
$this->verbose = $verbose;
}
public function checkEnvironment(): bool {
// Check if the version of xgettext is at least 0.18.3
$output = [];
exec('xgettext --version', $output);
// we assume the first line looks like this 'xgettext (GNU gettext-tools) 0.19.3'
$version = trim(substr($output[0], 29));
$this->log('xgettext version: '. $version);
if (version_compare($version, '0.18.3', '<')) {
echo 'Minimum expected version of xgettext is 0.18.3. Detected: ' . $version . '".' . PHP_EOL;
return false;
}
$this->findApps(getcwd());
if (count($this->appPaths) === 0) {
echo 'Could not find translatable apps. Make sure that the folder "l10n" is present.' . PHP_EOL;
return false;
}
return true;
}
public function createPotFiles(): void {
// Recreate folder for the templates
$this->rrmdir($this->translationPath . '/templates');
mkdir($this->translationPath . '/templates');
// iterate over all apps
foreach ($this->appPaths as $appPath) {
$this->log('Application path: ' . $appPath);
$app = new TranslatableApp($appPath, $this->translationPath, $this);
$app->createOrCheckPotFile();
}
}
public function convertPoFiles(): void {
foreach ($this->appPaths as $appPath) {
$this->log('Application path: ' . $appPath);
$app = new TranslatableApp($appPath, $this->translationPath, $this);
$app->createNextcloudFiles();
}
}
public function checkFiles(): void {
// iterate over all apps
foreach ($this->appPaths as $appPath) {
$this->log('Application path: ' . $appPath);
$app = new TranslatableApp($appPath, $this->translationPath, $this);
$app->createOrCheckPotFile(true);
}
}
private function findApps(string $path): void {
$directoryectoryContent = scandir($path);
foreach ($directoryectoryContent as $entry) {
if ($entry[0] === '.') {
continue;
}
$newPath = $path . '/' . $entry;
if (!is_dir($newPath)) {
continue;
}
if ($entry === 'node_modules') {
continue;
}
if ($entry === 'l10n') {
$this->appPaths[] = $path;
} else {
$this->findApps($newPath);
}
}
}
private function rrmdir(string $path): void {
if (!is_dir($path)) {
return;
}
$directory = opendir($path);
while (false !== ($entry = readdir($directory))) {
if (($entry !== '.') && ($entry !== '..')) {
$fullPath = $path . '/' . $entry;
if (is_dir($fullPath)) {
$this->rrmdir($fullPath);
} else {
unlink($fullPath);
}
}
}
closedir($directory);
rmdir($path);
}
public function log(string $message): void {
if ($this->verbose === 0) {
return;
}
echo ' > ' . $message . PHP_EOL;
}
}
// arguments handle
$task = '';
$usage = false;
$verbose = 0;
$returnValue = 0;
$toolName = 'translationtool';
$index = 0;
foreach ($argv as $arg) {
$index++;
if ($index === 1) {
$toolName = $arg;
continue;
}
switch($arg) {
case '-h':
case '--help':
$usage = true;
break;
case '-v':
case '--verbose':
$verbose++;
break;
case 'create-pot-files':
case 'convert-po-files':
case 'check-files':
$task = $arg;
break;
default:
echo 'Unknown command parameter : ' . $arg . PHP_EOL;
$usage = true;
$returnValue = 1;
break;
}
}
// read the command line arguments
if(empty($task) && !$usage) {
echo 'Missing arguments' . PHP_EOL;
$usage = true;
$returnValue = 1;
}
if ($usage) {
echo 'Usage:' . PHP_EOL;
echo ' ' . $toolName . ' <task> [<appName>]' . PHP_EOL;
echo 'Arguments:' . PHP_EOL;
echo ' task: One of: create-pot-files, convert-po-files, check-files' . PHP_EOL;
echo 'Options:'. PHP_EOL;
echo ' -v, --verbose Verbose mode'. PHP_EOL;
echo ' -h, --help Display command usage'. PHP_EOL;
exit($returnValue);
}
$tool = new TranslationTool();
$tool->setVerbose($verbose);
if (!$tool->checkEnvironment()) {
exit(1);
}
if ($task === 'create-pot-files') {
$tool->createPotFiles();
} elseif ($task === 'convert-po-files') {
$tool->convertPoFiles();
} elseif ($task === 'check-files') {
$tool->checkFiles();
} else {
echo 'Unknown task: "' . $task . '".' . PHP_EOL;
exit(1);
}