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 thread is resolved. Here is a description of the problem and solution.

Problem:
Make my new spanish translated home page look the same as the original english. The page contains FAQ elements added by the theme.

Solution:
In order to translate the content of the FAQ elements, you need to follow the steps presented here https://wpml.org/documentation/support/translating-urlencoded-shortcodes/

This means that in the WPML → Settings → Custom XML Configuration tab, you need to add this code:

<wpml-config>
    <shortcodes>
        <shortcode>
            <tag>supro_faqs</tag>
            <attributes>
                <attribute>title</attribute>
                <attribute type="area" encoding="urlencoded_json">faqs</attribute>
            </attributes>
        </shortcode>
    </shortcodes>
</wpml-config>

and this code to the end of the functions.php file of the theme:

add_filter( 'wpml_pb_shortcode_encode', 'wpml_pb_shortcode_encode_urlencoded_json', 10, 3 );
function wpml_pb_shortcode_encode_urlencoded_json( $string, $encoding, $original_string ) {
    if ( 'urlencoded_json' === $encoding ) {
        $output = array();
        foreach ( $original_string as $combined_key => $value ) {
            $parts = explode( '_', $combined_key );
            $i = array_pop( $parts );
            $key = implode( '_', $parts );
            $output[ $i ][ $key ] = $value;
        }
        $string = urlencode( json_encode( $output ) );
    }
    return $string;
}
 
add_filter( 'wpml_pb_shortcode_decode', 'wpml_pb_shortcode_decode_urlencoded_json', 10, 3 );
function wpml_pb_shortcode_decode_urlencoded_json( $string, $encoding, $original_string ) {
    if ( 'urlencoded_json' === $encoding ) {
        $rows = json_decode( urldecode( $original_string ), true );
        $string = array();
        foreach ( $rows as $i => $row ) {
            foreach ( $row as $key => $value ) {
            if ( in_array( $key, array( 'text', 'title', 'features', 'substring', 'btn_text', 'title', 'desc', 'y_values' ) ) ) {
                    $string[ $key . '_' . $i ] = array( 'value' => $value, 'translate' => true );
                } else {
                    $string[ $key . '_' . $i ] = array( 'value' => $value, 'translate' => false );
                }
            }
        }
    }
    return $string;
}

Relevant Documentation:
https://wpml.org/documentation/support/translating-urlencoded-shortcodes/

Tagged: 

This topic contains 12 replies, has 2 voices.

Last updated by andres 1 week, 6 days ago.

Assigned support staff: Radu.

Author Posts
September 30, 2019 at 8:44 pm #4667529

andres

I am trying to:

Make my new spanish translated home page look the same as the original english.

Link to a page where the issue can be seen:

original: hidden link
spanish translation: hidden link

I expected to see:
the same spacing between elements. the same color backgrounds.

Instead, I got:
different spacing between elements. different color backgrounds.

October 1, 2019 at 4:58 am #4668751

Radu
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hey Andres,

Thank you for reaching out the WPML support!

As I can see, you're using WPBakery to create the content from the pages. Apart from the style, I can see that some content like the one from What our Customers say or Perfect for home and work is not available either.

In this case, a couple elements that you're using on the page might not be compatible with the WPML. That's why it would be great if you could give me access to the dashboard area. This way I'll have a closer look at this and see what can be done to make the Spanish translation have the same look.

The next reply is set to be private so you can safely send me the credentials.

Thanks,
Radu

October 7, 2019 at 12:13 pm #4707007

Radu
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hey Andres,

I just had another look at the homepage (both the original and the translated one), and everything looks better now. Can you tell me if you managed to sort this out in the meantime? I compared the spaces and the content from both pages and nothing seems to be different now.

If there's anything that slipped through my fingers and you still need help with on this side, please let me know.

Thanks,
Radu

October 7, 2019 at 1:21 pm #4707777

andres

Hi Radu

I was able yo sort out the problem of spacings in my home page, but please read my last private message. The faqs page isnt working because I am not able to make the short code translation appear when I save it.

October 8, 2019 at 9:49 am #4713739

Radu
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hey Andres,

You did a good job about the XML config code. I just edited the English FAQ page, made a small change to the last element, updated the page, updated the translation too, and then check again the page. This time, the translation worked fine.

Can you try to do the same and see if things are working fine this time, please? Just simply make a change to one of the FAQs (like adding one more point at the end of a sentence), update the page, update the translation too, and see if the translation is working fine this time.

Thanks,
Radu

October 8, 2019 at 3:01 pm #4716571

andres

Thanks Radu

Sorry but it still doesn't seem to work for me. The titles are translated, but the 'faq' shortcode contents don't appear in the webpage.

I attach a screenshot - on the left you can see the strings I translated for the 'faq' shortcode. On the right you can see the spanish version of the page which still shows english.

October 9, 2019 at 2:50 pm #4723827

andres

Hi Radu

Sorry to write again but please can you look at this issue again? We need to publish this page asap and I want to use the wpml system rather than translate 2 pages independently. Thanks!

October 9, 2019 at 8:45 pm #4725551

Radu
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hey Andres,

I checked this out a couple times today, trying to figure it out what's wrong here. You did a great job adding the code as presented in this article https://wpml.org/documentation/support/translating-urlencoded-shortcodes/. I just had to change this line:

if ( in_array( $key, array( 'text', 'title', 'features', 'substring', 'btn_text', 'label', 'value', 'y_values' ) ) )

to

if ( in_array( $key, array( 'desc', 'text', 'title', 'features', 'substring', 'btn_text', 'title', 'desc', 'y_values') ) )

However, even though everything is set up as it should, this shortcode is still not translating. In this case, could you send me a copy of the theme (as I can see, this shortcode is a part of the theme) so I can install it on a clean website, add again the custom code and XML, and see if I can replicate the issue, please? This way, I'll be able to pass it to my colleagues and let them have a look. I'm sure that we'll be able to sort this out and get things back to normal.

I'll keep an eye on this ticket and just into it as soon as you reply me back so we can get it fixed as soon as we can.

Thanks,
Radu

October 9, 2019 at 9:33 pm #4725681

andres

Thanks very much for persevering Radu!

I uploaded the Supro theme to my google drive, so you can download here:
hidden link

I really hope this can be made to work as I love the theme, and it seems to have good support from the devs.

Thanks again

October 10, 2019 at 7:44 am #4728087

Radu
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hey Andres,

Could you give me access to the file, please? I just requested access so you should receive an email. Once I download the theme, I'll start testing the FAQ element.

Thanks,
Radu

October 10, 2019 at 12:30 pm #4730299

andres

Done! Please let me know if you have any further issues with the link.

October 10, 2019 at 1:26 pm #4730859

Radu
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hey Andres,

Could you check the Spanish FAQs page here hidden link and tell me if the right content is displayed now, please?

I created here the test page on my website hidden link so once I managed to get everything work, I copied the code I used, on your website. I think that a line from the code you added to functions.php was commented.

Thanks,
Radu

October 10, 2019 at 2:02 pm #4731191

andres

My issue is resolved now. Thank you!