Fix the issue of marketing optin block translation not getting added

Since WP 6.0 we can no longer leave translation_path in block
settings empty and expect to receive the fallback thus we need
to add the fallback ourselves.

[MAILPOET-4435]
This commit is contained in:
Sam Najian
2022-06-15 10:15:52 +02:00
committed by Veljko V
parent d3a5525095
commit fe6013f0cf

View File

@ -86,11 +86,14 @@ class MarketingOptinBlock implements IntegrationInterface {
*/
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;
}
$editorTranslations = <<<JS
( function( domain, translations ) {
var localeData = translations.locale_data[ domain ] || translations.locale_data.messages;
localeData[""].domain = domain;
wp.i18n.setLocaleData( localeData, domain );
} )( "mailpoet", { "locale_data": { "messages": { "": {} } } } );
JS;
$translations = [
'' => ['domain' => 'messages'],
'marketing-opt-in-label' => [__('Marketing opt-in', 'mailpoet')],