Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 3 replies, has 2 voices.

Last updated by ivanS-69 1 year, 4 months ago.

Assisted by: Christopher Amirian.

Author Posts
June 29, 2023 at 12:08 pm #13917907

ivanS-69

Hi!
We created wpml-config.xml file where all translatable block attributes are listed.
Most of the attributes work fine, but we're having issues with a field that is storing an array of objects.

This is the block structure:
<!-- wp:custom-namespace/card-customer-story {
"cardCustomerStoryCardCustomerStoryHeadingContent":"Title",
"cardCustomerStoryCardCustomerStoryMetrics":[
{
"id":1,
"metric":"100%",
"description":"satisfied customers"
}
]
} /-->

Everything is good for the 'cardCustomerStoryCardCustomerStoryHeadingContent' attribute, but values inside 'cardCustomerStoryCardCustomerStoryMetrics' are not shown inside the translation manager.

The configuration we used:
<gutenberg-block type="custom-namespace/card-customer-story" translate="1">
<key name="cardCustomerStoryCardCustomerStoryHeadingContent" />
<key name="cardCustomerStoryCardCustomerStoryMetrics" encoding="json">
<key name="*">
<key name="metric" />
<key name="description" />
</key>
</key>
</gutenberg-block>

This is mentioned under the 'URL-encoded JSON strings' paragraph on the page: https://wpml.org/documentation/support/language-configuration-files/#6-2-translation-of-block-attributes. Unfortunately, it doesn't work in our case.

I'm getting a PHP warning: urldecode() expects parameter 1 to be string, array given in .../plugins/sitepress-multilingual-cms/addons/wpml-page-builders/classes/Integrations/Gutenberg/strings-in-block/class-attributes.php on line 44.

I'm aware this might not be the right approach, but I haven't found anything else related to it. Do you have an idea how to solve this?

July 2, 2023 at 8:20 am #13928679

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

Would you please test this without wildcards and see if it works?

<wpml-config>
    <gutenberg-block type="custom-namespace/card-customer-story" translate="1">
        <key name="cardCustomerStoryCardCustomerStoryHeadingContent" />
        <key name="cardCustomerStoryCardCustomerStoryMetrics" encoding="json">
            <key name="metric" />
            <key name="description" />
        </key>
    </gutenberg-block>
</wpml-config>

It seems that the content is too complicated inside for wpml to understand. But I can try to see if it is possible.

Would you please install the Gutenberg block here so I will have a playground to check?

hidden link

Thanks.

July 3, 2023 at 2:02 pm #13933631

ivanS-69

Hi Cristopher!
It seems that this code worked:

<gutenberg-block type="custom-namespace/card-customer-story" translate="1">
    <key name="cardCustomerStoryCardCustomerStoryHeadingContent" />
    <key name="cardCustomerStoryCardCustomerStoryMetrics">
        <key name="*">
            <key name="metric" />
            <key name="description" />
        </key>
    </key>
</gutenberg-block>

The problem was some kind of caching. When changes are made in wpml-config.xml file, they're not recognized. But when I enter some code in 'Custom XML Configuration' in settings, save it, and then delete that code, file settings are applied again and new changes are recognized. Not sure why that is happening, but this 'hack' works in my case.

Thank you for your assistance.