-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakePotCommand.php
72 lines (58 loc) · 1.83 KB
/
MakePotCommand.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
<?php
namespace Timber\WpI18nTwig;
use Gettext\Translation;
use WP_CLI;
use WP_CLI\I18n\MakePotCommand as BaseMakePotCommand;
use WP_CLI\I18n\PotGenerator;
use WP_CLI\Utils;
class MakePotCommand extends BaseMakePotCommand {
/**
* @var bool
*/
protected $skip_twig = false;
// Dummy override so longdesc is preferred to parent Docblock
// @codingStandardsIgnoreLine
public function __invoke( $args, $assoc_args ) {
return parent::__invoke( $args, $assoc_args );
}
public function handle_arguments( $args, $assoc_args ) {
$this->skip_twig = Utils\get_flag_value( $assoc_args, 'skip-twig', $this->skip_twig );
parent::handle_arguments( $args, $assoc_args );
}
protected function extract_strings() {
$translations = parent::extract_strings();
try {
if ( ! $this->skip_twig ) {
$options = [
'include' => $this->include,
'exclude' => $this->exclude,
'extensions' => [ 'twig' ],
'addReferences' => $this->location,
];
TwigCodeExtractor::fromDirectory( $this->source, $translations, $options );
}
} catch ( \Exception $e ) {
WP_CLI::error( $e->getMessage() );
}
foreach ( $this->exceptions as $file => $exception_translations ) {
/** @var Translation $exception_translation */
foreach ( $exception_translations as $exception_translation ) {
if ( ! $translations->find( $exception_translation ) ) {
continue;
}
if ( $this->subtract_and_merge ) {
$translation = $translations[ $exception_translation->getId() ];
$exception_translation->mergeWith( $translation );
}
unset( $translations[ $exception_translation->getId() ] );
}
if ( $this->subtract_and_merge ) {
PotGenerator::toFile( $exception_translations, $file );
}
}
if ( ! $this->skip_audit ) {
$this->audit_strings( $translations );
}
return $translations;
}
}