diff --git a/assets/js/src/marketing_optin_block/edit.tsx b/assets/js/src/marketing_optin_block/edit.tsx
index 411de6a63e..a658187f78 100644
--- a/assets/js/src/marketing_optin_block/edit.tsx
+++ b/assets/js/src/marketing_optin_block/edit.tsx
@@ -20,14 +20,11 @@ const { optinEnabled, defaultText } = getSetting('mailpoet_data');
const EmptyState = (): JSX.Element => (
}
- label={__('Marketing opt-in', 'mailpoet')}
+ label={__('marketing-opt-in-label', 'mailpoet')}
className="wp-block-mailpoet-newsletter-block-placeholder"
>
- {__(
- 'MailPoet marketing opt-in would be shown here if enabled. You can enable from the settings page.',
- 'mailpoet'
- )}
+ {__('marketing-opt-in-not-shown', 'mailpoet')}
);
diff --git a/lib/PostEditorBlocks/MarketingOptinBlock.php b/lib/PostEditorBlocks/MarketingOptinBlock.php
index 43ae0a9706..0eaab8af55 100644
--- a/lib/PostEditorBlocks/MarketingOptinBlock.php
+++ b/lib/PostEditorBlocks/MarketingOptinBlock.php
@@ -48,6 +48,7 @@ class MarketingOptinBlock implements IntegrationInterface {
$script_asset['version'],
true
);
+ $this->registerEditorTranslations();
}
/**
@@ -76,4 +77,27 @@ class MarketingOptinBlock implements IntegrationInterface {
public function get_script_data() { // phpcs:ignore
return $this->options;
}
+
+ /**
+ * Workaround for registering script translations.
+ * Currently, we don't generate translation files for scripts. This method enqueues an inline script
+ * that renders same output as a script translation file would render, when rendered via wp_scripts()->print_translations.
+ * Note that keys need to match strings in JS files
+ */
+ private function registerEditorTranslations() {
+ $handle = 'mailpoet-marketing-optin-block-editor-script';
+ $editorTranslations = $this->wp->getWpScripts()->print_translations($handle, false);
+ // mailpoet-marketing-optin-block-editor-script is not enqueued
+ if ($editorTranslations === false) {
+ return;
+ }
+ $translations = [
+ '' => ['domain' => 'messages'],
+ 'marketing-opt-in-label' => [__('Marketing opt-in', 'mailpoet')],
+ 'marketing-opt-in-not-shown' => [__('MailPoet marketing opt-in would be shown here if enabled. You can enable from the settings page.', 'mailpoet')],
+ 'marketing-opt-in-enable' => [__('Enable opt-in for Checkout', 'mailpoet')],
+ ];
+ $editorTranslations = str_replace('{ "messages": { "": {} }', '{ "messages": ' . json_encode($translations), $editorTranslations);
+ $this->wp->wpAddInlineScript($handle, $editorTranslations, 'before');
+ }
}
diff --git a/lib/WP/Functions.php b/lib/WP/Functions.php
index 35b169d80d..faec5cb9d2 100644
--- a/lib/WP/Functions.php
+++ b/lib/WP/Functions.php
@@ -752,4 +752,11 @@ class Functions {
public function wpSetScriptTranslations(string $handle, string $domain = 'default', string $path = null): bool {
return wp_set_script_translations($handle, $domain, $path);
}
+
+ /**
+ * @return \WP_Scripts
+ */
+ public function getWpScripts() {
+ return wp_scripts();
+ }
}