Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions features/makepot.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3467,6 +3467,77 @@ Feature: Generate a POT file of a WordPress project
msgid "anotherkeyword"
"""

Scenario: Falls back to bundled schemas when remote schemas cannot be downloaded
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.php file:
"""
<?php
/**
* Plugin Name: Foo Plugin
*/
"""
And a foo-plugin/block.json file:
"""
{
"name": "my-plugin/notice",
"title": "Notice",
"category": "common",
"textdomain": "foo-plugin"
}
"""
And a foo-plugin/theme.json file:
"""
{
"version": 1,
"settings": {
"color": {
"palette": [
{ "slug": "black", "color": "#000000", "name": "Black" }
]
}
}
}
"""
# A response without a header/body separator makes Requests throw, which
# WP_CLI\Utils\http_request() turns into a RuntimeException, as on a network error.
And that HTTP requests to https://develop.svn.wordpress.org/trunk/src/wp-includes/ will respond with:
"""
HTTP/1.1 503 Service Unavailable
"""

When I try `wp i18n make-pot foo-plugin --debug`
Then STDOUT should contain:
"""
Success: POT file successfully generated.
"""
And STDERR should contain:
"""
Failed to download from URL https://develop.svn.wordpress.org/trunk/src/wp-includes/block-i18n.json
"""
And STDERR should contain:
"""
Failed to download from URL https://develop.svn.wordpress.org/trunk/src/wp-includes/theme-i18n.json
"""
And STDERR should contain:
"""
Remote file could not be accessed, will use local file as fallback
"""
And STDERR should not contain:
"""
Error:
"""
And the return code should be 0
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgctxt "block title"
msgid "Notice"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgctxt "Color name"
msgid "Black"
"""

Scenario: Ignores block.json files with other text domain
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.php file:
Expand Down
13 changes: 10 additions & 3 deletions src/JsonSchemaExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Gettext\Extractors\Extractor;
use Gettext\Translations;
use RuntimeException;
use WP_CLI;
use WP_CLI\Utils;

Expand Down Expand Up @@ -192,9 +193,15 @@ private static function remote_get( $url ) {
return '';
}

$headers = [ 'Content-Type' => 'application/json' ];
$options = [ 'halt_on_error' => false ];
$response = Utils\http_request( 'GET', $url, null, $headers, $options );
$headers = [ 'Content-Type' => 'application/json' ];
$options = [ 'halt_on_error' => false ];

try {
$response = Utils\http_request( 'GET', $url, null, $headers, $options );
} catch ( RuntimeException $exception ) {
WP_CLI::debug( "Failed to download from URL {$url}: {$exception->getMessage()}", 'make-pot' );
return '';
}

if (
! $response->success
Expand Down
Loading