Add a check if translations are ready
[MAILPOET-3807]
This commit is contained in:
17
RoboFile.php
17
RoboFile.php
@ -769,12 +769,29 @@ class RoboFile extends \Robo\Tasks {
|
|||||||
$this->say('Translations ' . $result['data']);
|
$this->say('Translations ' . $result['data']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is part of release publish script. It checks if translations are ready at Wordpress.com translations system
|
||||||
|
* @param string $version
|
||||||
|
*/
|
||||||
|
public function translationsCheckLanguagePacks($version) {
|
||||||
|
$translations = new \MailPoetTasks\Release\TranslationsController();
|
||||||
|
$result = $translations->checkIfTranslationsAreReady($version);
|
||||||
|
if (!$result['success']) {
|
||||||
|
$this->yell('Translations are not ready yet on WordPress.com. ' . $result['data'], 40, 'red');
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
$this->say('Translations check passed');
|
||||||
|
}
|
||||||
|
|
||||||
public function releasePublish($version = null) {
|
public function releasePublish($version = null) {
|
||||||
$version = $this->releaseVersionGetPrepared($version);
|
$version = $this->releaseVersionGetPrepared($version);
|
||||||
return $this->collectionBuilder()
|
return $this->collectionBuilder()
|
||||||
->addCode(function () use ($version) {
|
->addCode(function () use ($version) {
|
||||||
return $this->releaseCheckPullRequest($version);
|
return $this->releaseCheckPullRequest($version);
|
||||||
})
|
})
|
||||||
|
->addCode(function () use ($version) {
|
||||||
|
return $this->translationsCheckLanguagePacks($version);
|
||||||
|
})
|
||||||
->addCode(function () {
|
->addCode(function () {
|
||||||
return $this->releaseDownloadZip();
|
return $this->releaseDownloadZip();
|
||||||
})
|
})
|
||||||
|
@ -3,16 +3,17 @@
|
|||||||
namespace MailPoetTasks\Release;
|
namespace MailPoetTasks\Release;
|
||||||
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use GuzzleHttp\RequestOptions;
|
||||||
|
|
||||||
class TranslationsController {
|
class TranslationsController {
|
||||||
private const API_IMPORT_BASE_URI = 'https://translate.wordpress.com/api/import-transifex/';
|
private const API_IMPORT_BASE_URI = 'https://translate.wordpress.com/api/import-transifex/';
|
||||||
|
private const API_CHECK_BASE_URI = 'https://translate.wordpress.com/api/translations-updates/mailpoet/';
|
||||||
|
|
||||||
public function importTransifex(string $version, $project = 'mailpoet'): array {
|
public function importTransifex(string $version, string $project = 'mailpoet'): array {
|
||||||
$httpClient = new Client([
|
$httpClient = new Client([
|
||||||
'base_uri' => self::API_IMPORT_BASE_URI . $project . '/',
|
'base_uri' => self::API_IMPORT_BASE_URI . $project . '/',
|
||||||
]);
|
]);
|
||||||
$response = $httpClient->post($version);
|
$response = $httpClient->post($version);
|
||||||
$response->getStatusCode();
|
|
||||||
if ($response->getStatusCode() !== 200) {
|
if ($response->getStatusCode() !== 200) {
|
||||||
return [
|
return [
|
||||||
'success' => false,
|
'success' => false,
|
||||||
@ -29,7 +30,44 @@ class TranslationsController {
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkIfTranslationsAreReady(string $version): bool {
|
public function checkIfTranslationsAreReady(string $version, string $project = 'mailpoet'): array {
|
||||||
return true;
|
$httpClient = new Client();
|
||||||
|
$payload = [
|
||||||
|
'locales' => ['de_DE_formal', 'fr_FR'],
|
||||||
|
'plugins' => [],
|
||||||
|
];
|
||||||
|
$payload['plugins'][$project] = ['version' => $version];
|
||||||
|
$response = $httpClient->post(self::API_CHECK_BASE_URI, [RequestOptions::JSON => $payload]);
|
||||||
|
if ($response->getStatusCode() !== 200) {
|
||||||
|
return [
|
||||||
|
'success' => false,
|
||||||
|
'data' => 'Failed downloading response, status code: ' . $response->getStatusCode(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$result = json_decode($response->getBody()->getContents(), true);
|
||||||
|
if (!is_array($result) || !isset($result['success']) || !isset($result['data']) || !isset($result['data'][$project])) {
|
||||||
|
return [
|
||||||
|
'success' => false,
|
||||||
|
'data' => 'Failed preparing translations - malformed response: ' . $response->getBody()->getContents(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $result['data'][$project];
|
||||||
|
$locales = [];
|
||||||
|
foreach ($data as $languageResponse) {
|
||||||
|
$locales[$languageResponse['wp_locale']] = $languageResponse['wp_locale'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($locales['de_DE_formal']) && isset($locales['fr_FR'])) {
|
||||||
|
return [
|
||||||
|
'success' => true,
|
||||||
|
'data' => '',
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
return [
|
||||||
|
'success' => false,
|
||||||
|
'data' => '',
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user