Make all automation strings in PHP translatable, improve context/comments

[MAILPOET-4611]
This commit is contained in:
Jan Jakes
2022-10-20 13:10:43 +02:00
committed by Aschepikov
parent a7277f3437
commit 421549d6ee
5 changed files with 13 additions and 5 deletions

View File

@ -3,11 +3,11 @@
namespace MailPoet\Automation\Engine\Builder; namespace MailPoet\Automation\Engine\Builder;
use MailPoet\Automation\Engine\Data\Workflow; use MailPoet\Automation\Engine\Data\Workflow;
use MailPoet\Automation\Engine\Exceptions;
use MailPoet\Automation\Engine\Exceptions\InvalidStateException; use MailPoet\Automation\Engine\Exceptions\InvalidStateException;
use MailPoet\Automation\Engine\Storage\WorkflowStorage; use MailPoet\Automation\Engine\Storage\WorkflowStorage;
use MailPoet\Automation\Engine\Storage\WorkflowTemplateStorage; use MailPoet\Automation\Engine\Storage\WorkflowTemplateStorage;
use MailPoet\Automation\Engine\Validation\WorkflowValidator; use MailPoet\Automation\Engine\Validation\WorkflowValidator;
use MailPoet\UnexpectedValueException;
class CreateWorkflowFromTemplateController { class CreateWorkflowFromTemplateController {
/** @var WorkflowStorage */ /** @var WorkflowStorage */
@ -32,7 +32,7 @@ class CreateWorkflowFromTemplateController {
public function createWorkflow(string $slug): Workflow { public function createWorkflow(string $slug): Workflow {
$template = $this->templateStorage->getTemplateBySlug($slug); $template = $this->templateStorage->getTemplateBySlug($slug);
if (!$template) { if (!$template) {
throw UnexpectedValueException::create()->withMessage('Template not found.'); throw Exceptions::workflowTemplateNotFound($slug);
} }
$workflow = $template->getWorkflow(); $workflow = $template->getWorkflow();

View File

@ -31,6 +31,7 @@ class Exceptions {
private const WORKFLOW_NOT_VALID = 'mailpoet_automation_workflow_not_valid'; private const WORKFLOW_NOT_VALID = 'mailpoet_automation_workflow_not_valid';
private const MISSING_REQUIRED_SUBJECTS = 'mailpoet_automation_missing_required_subjects'; private const MISSING_REQUIRED_SUBJECTS = 'mailpoet_automation_missing_required_subjects';
private const WORKFLOW_NOT_TRASHED = 'mailpoet_automation_workflow_not_trashed'; private const WORKFLOW_NOT_TRASHED = 'mailpoet_automation_workflow_not_trashed';
private const WORKFLOW_TEMPLATE_NOT_FOUND = 'mailpoet_automation_workflow_template_not_found';
public function __construct() { public function __construct() {
throw new InvalidStateException( throw new InvalidStateException(
@ -220,4 +221,11 @@ class Exceptions {
// translators: %d is the ID of the workflow. // translators: %d is the ID of the workflow.
->withMessage(sprintf(__("Can't delete workflow with ID '%d' because it was not trashed.", 'mailpoet'), $id)); ->withMessage(sprintf(__("Can't delete workflow with ID '%d' because it was not trashed.", 'mailpoet'), $id));
} }
public static function workflowTemplateNotFound(string $id): NotFoundException {
return NotFoundException::create()
->withErrorCode(self::WORKFLOW_TEMPLATE_NOT_FOUND)
// translators: %d is the ID of the workflow template.
->withMessage(sprintf(__("Workflow template with ID '%d' not found.", 'mailpoet'), $id));
}
} }

View File

@ -24,7 +24,7 @@ abstract class Exception extends PhpException implements RestException {
string $errorCode = null, string $errorCode = null,
Throwable $previous = null Throwable $previous = null
) { ) {
parent::__construct($message ?? 'Unknown error.', 0, $previous); parent::__construct($message ?? __('Unknown error.', 'mailpoet'), 0, $previous);
$this->errorCode = $errorCode ?? 'mailpoet_automation_unknown_error'; $this->errorCode = $errorCode ?? 'mailpoet_automation_unknown_error';
} }

View File

@ -27,7 +27,7 @@ class DelayAction implements Action {
} }
public function getName(): string { public function getName(): string {
return __('Delay', 'mailpoet'); return _x('Delay', 'noun', 'mailpoet');
} }
public function getArgsSchema(): ObjectSchema { public function getArgsSchema(): ObjectSchema {

View File

@ -41,7 +41,7 @@ class UserRegistrationTrigger implements Trigger {
} }
public function getName(): string { public function getName(): string {
return __('Subscribed to segment', 'mailpoet'); return __('WordPress user registers', 'mailpoet');
} }
public function getArgsSchema(): ObjectSchema { public function getArgsSchema(): ObjectSchema {