-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathBlockExtractor.php
More file actions
40 lines (31 loc) · 914 Bytes
/
BlockExtractor.php
File metadata and controls
40 lines (31 loc) · 914 Bytes
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
<?php
namespace WP_CLI\I18n;
use Gettext\Translations;
use WP_CLI;
final class BlockExtractor extends JsonSchemaExtractor {
/**
* @inheritdoc
*/
public static function fromString( $text, Translations $translations, array $options = [] ) {
$file = $options['file'];
WP_CLI::debug( "Parsing file $file", 'make-pot' );
$json = json_decode( $text, true );
if ( null === $json ) {
WP_CLI::debug(
sprintf(
'Could not parse file %1$s: error code %2$s',
$file,
json_last_error()
),
'make-pot'
);
return;
}
$domain = isset( $json['textdomain'] ) ? $json['textdomain'] : null;
// Always allow missing domain or when --ignore-domain is used, but skip if domains don't match.
if ( null !== $translations->getDomain() && null !== $domain && $domain !== $translations->getDomain() ) {
return;
}
parent::fromString( $text, $translations, $options );
}
}