WPML: Translating blocks that aren’t translatable

A follow up to yesterday’s post: Getwid-Megamenu WPML

I ran into an issue that the Previous & Next buttons in my single-post template were not translatable in WPML.

The first step was to take a look at the HTML for the block from the editor:

<!-- wp:post-navigation-link {"type":"previous","label":"Previous Story","arrow":"arrow"} /-->

We can see that the text we want to translate is in the “label” field.

In a wpml-config.xml file (in your theme), or in WPML->Settings->Custom XML Configuration you can set that a field in a blocks attributes is translatable. Here is how to do that for the block above:

<wpml-config>
  <gutenberg-blocks>
    <gutenberg-block type="core/post-navigation-link" translate="1">
      <key name="label" />
    </gutenberg-block>
  </gutenberg-blocks>
</wpml-config>

Save that, then send the template to translation again and it should now be able to be translated.