Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
You are trying to translate the vc_progress_bar shortcode using WPML, but the value and label fields do not appear in the translation editor despite following the steps in the documentation.
Solution:
We recommend adding specific code to your functions.php file to handle the encoding and decoding of the vc_progress_bar shortcode. Here is the code you should add:

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

This solution might be outdated or not applicable to your specific case. We highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If this does not resolve your issue, please open a new support ticket at WPML support forum.

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.

No supporters are available to work today on this forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

This topic contains 3 replies, has 2 voices.

Last updated by Osama Mersal 1 month, 3 weeks ago.

Assisted by: Osama Mersal.

Author Posts
September 20, 2024 at 12:02 pm #16202763

Rico Heinrich

Background of the issue:
I would like to translate the shortcode vc_progress_bar as described here: https://wpml.org/documentation/support/translating-urlencoded-shortcodes/. I followed all the steps.

Symptoms:
Value and label fields do not appear in the translation editor.

Questions:
Why do the value and label fields not appear in the translation editor after following the steps in the documentation?

September 22, 2024 at 9:39 am #16205737

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

Thanks for contacting WPML forums support. I'll be glad to help you today.

First of all, sorry for the late reply; it was due to a higher workload.

Please log in to this hidden link">sandbox site and install the WP Bakery plugin.

After that, please create a test page and use the Progress Bar module to replicate the issue.

If the issue is replicable, please let me know to check it and consult our compatibility team.

Best regards,
Osama

September 23, 2024 at 2:42 pm #16210391

Rico Heinrich

Hello Osama,

I'm afraid I cannot install the WP Bakery plugin because there is only a paid version.

We use it as part of the Uncode theme which is only available as a paid version too.

I'm not sure how I can install that in the sandbox site and if it is even allowed by the developer.

However, we have a testing site which is a copy of our live site. You could check it there, if possible.

September 23, 2024 at 3:36 pm #16210650

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

I installed the WP Bakery plugin on the sandbox site. Please check this hidden link">page.

I was able to translate it by adding the following code to the functions.php file:

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', 'label', 'value', 'y_values' ) ) ) {
                    $string[ $key . '_' . $i ] = array( 'value' => $value, 'translate' => true );
                } else {
                    $string[ $key . '_' . $i ] = array( 'value' => $value, 'translate' => false );
                }
            }
        }
    }
    return $string;
}

Best regards,
Osama

September 23, 2024 at 4:42 pm #16211039

Rico Heinrich

Thank you very much Osama, it works now.

Maybe there was something wrong in the code which I copied from the support ticket mentioned in the first comment.

Best regards,

Rico