Skip to content Skip to sidebar

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

Problem:
The client was unable to translate the content within tables on specific web pages using WPML, as the content did not appear when clicking on 'Edit Translation'.

Solution:
We identified that the content within the tables was managed by a shortcode. To enable translation for these shortcodes, we recommended the following steps:
1. Register the shortcode attributes for translation by adding the following code to the WPML > Settings > Custom XML Configuration tab:

<shortcode>
  <tag>tek_pricing</tag>
  <attributes>
    <attribute label="Pricing title">pricing_title</attribute>
    <attribute label="Pricing time">pricing_time</attribute>
    <attribute label="Pricing button text">pricing_button_text</attribute>
    <attribute type="area" encoding="urlencoded_json">pricing_option</attribute>
  </attributes>
</shortcode>

2. Add the following code to the file functions.php in the child theme folder to handle the encoding and decoding of the URL-encoded JSON:

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

3. Edit the page in the English language, click on Update, and then update the translation page. The pricing option content should now be available in the translation editor.

If this solution does not resolve your issue, or if it seems outdated or irrelevant to your specific case, we highly recommend checking the related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If further assistance is needed, please open a new support ticket.

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 Long Nguyen 1 year, 3 months ago.

Assisted by: Long Nguyen.

Author Posts
September 9, 2024 at 4:03 pm

amandaR-4

Background of the issue:
I am unsure how to translate the tables on the following pages: hidden link and hidden link. I have machine translated the other content, but the content in the tables does not show up when I click on 'Edit Translation'.

Symptoms:
The content in the tables does not show up when I click on 'Edit Translation'.

Questions:
How do I translate the tables on the specified pages using WPML?

September 10, 2024 at 6:59 am #16159456

Long Nguyen
WPML Supporter since 02/2022

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi Amanda,

Thank you for contacting WPML support, I’m happy to help you with this issue.

When editing the SMS page in the Classic mode, I get the shortcode that renders the pricing table in the frontend:

[tek_pricing pricing_title="SMS Basic" pricing_price="995" sale_settings="sale-no" pricing_currency="currency-dollar" pricing_currency_position="currency-position-left" pricing_time="/year" pricing_subtitle="$260 yearly maintenance fee" pricing_icon_type="no_icon" pricing_option="%5B%7B%22pricing_row%22%3A%22%3Cspan%3EFile%20processing%20from%20most%20precision%20ag%20displays%3C%2Fspan%3E%22%2C%22pricing_row_icon%22%3A%22pricing-opt-no-icon%22%7D%2C%7B%22pricing_row%22%3A%22%3Cspan%3ESorts%20data%20by%20geography%3C%2Fspan%3E%22%2C%22pricing_row_icon%22%3A%22pricing-opt-no-icon%22%7D%2C%7B%22pricing_row%22%3A%22%3Cspan%3EGenerate%20crop%20plans%3C%2Fspan%3E%22%2C%22pricing_row_icon%22%3A%22pricing-opt-no-icon%22%7D%2C%7B%22pricing_row%22%3A%22%3Cspan%3ECreate%2C%20manage%2C%20and%20export%20guidance%20lines%3C%2Fspan%3E%22%2C%22pricing_row_icon%22%3A%22pricing-opt-no-icon%22%7D%2C%7B%22pricing_row%22%3A%22%3Cspan%3EPrint%20summary%20maps%2C%20charts%2C%20and%20reports%3C%2Fspan%3E%22%2C%22pricing_row_icon%22%3A%22pricing-opt-no-icon%22%7D%2C%7B%22pricing_row%22%3A%22%3Cspan%3EAerial%2FRoad%20backgrounds%3C%2Fspan%3E%22%2C%22pricing_row_icon%22%3A%22pricing-opt-no-icon%22%7D%2C%7B%22pricing_row%22%3A%22%3Cspan%3EWrite%20simple%20prescriptions%3C%2Fspan%3E%22%2C%22pricing_row_icon%22%3A%22pricing-opt-no-icon%22%7D%2C%7B%22pricing_row%22%3A%22%3Cspan%3EPrescription%20budget%20tool%3C%2Fspan%3E%22%2C%22pricing_row_icon%22%3A%22pricing-opt-no-icon%22%7D%2C%7B%22pricing_row%22%3A%22%3Cspan%3EQuery%20tools%20to%20analyze%20specific%20areas%3C%2Fspan%3E%22%2C%22pricing_row_icon%22%3A%22pricing-opt-no-icon%22%7D%2C%7B%22pricing_row%22%3A%22%3Cspan%3E%20Check%20for%20updates%3C%2Fspan%3E%22%2C%22pricing_row_icon%22%3A%22pricing-opt-no-icon%22%7D%2C%7B%22pricing_row%22%3A%22%3Cspan%3EView%20current%20and%20historical%20weather%20for%20fields%3C%2Fspan%3E%22%2C%22pricing_row_icon%22%3A%22pricing-opt-no-icon%22%7D%2C%7B%22pricing_row%22%3A%22%3Cspan%3EUse%20satellite%20(Sentinel)%20imagery%20to%20identify%20healthy%20trends%20in%20fields%3C%2Fspan%3E%22%2C%22pricing_row_icon%22%3A%22pricing-opt-no-icon%22%7D%2C%7B%22pricing_row%22%3A%22%3Cspan%3ESoil%20survey%20import%20(U.S.%20only)%3C%2Fspan%3E%22%2C%22pricing_row_icon%22%3A%22pricing-opt-no-icon%22%7D%2C%7B%22pricing_row%22%3A%22%3Cspan%3ESend%2FReceive%20files%20with%20AgFiniti*%3C%2Fspan%3E%22%2C%22pricing_row_tooltip%22%3A%22*Service%20available%20for%20purchase%22%2C%22pricing_row_icon%22%3A%22pricing-opt-no-icon%22%7D%5D" button_settings="enable-button" pricing_button_text="Purchase Now" button_action="button-action-link" pricing_button_link="<em><u>hidden link</u></em>" pricing_link_target="_self" pricing_button_enable_icon="no" pricing_scheme="DetailedStyle" highlight_plan="active" secondary_sale_settings="sale-no" css_animation=""]

the pricing options value is in the URL-encoded format, then I follow the documentation to register the shortcode attributes for translation
https://wpml.org/documentation/support/translating-urlencoded-shortcodes/

1. Add this code to WPML > Settings > Custom XML configuration tab.

<shortcode>
  <tag>tek_pricing</tag>
  <attributes>
    <attribute label="Pricing title">pricing_title</attribute>
    <attribute label="Pricing time">pricing_time</attribute>
    <attribute label="Pricing button text">pricing_button_text</attribute>
    <attribute type="area" encoding="urlencoded_json">pricing_option</attribute>
  </attributes>
</shortcode>

2. Add this code to the file functions.php in the child theme folder.

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

3. Edit the page in the English language > Click on Update > Update the translation page.
Now you can see the pricing option content is available in the translation editor as well.

Looking forward to your reply.
Thanks

Advanced Translation Editor - WPML 2024-09-10 13-52-32.png
September 10, 2024 at 2:31 pm #16162221

amandaR-4

Thank you for your help! The Portuguese translation did not update. It still does not recognize the text that needs to be translated.

I also need the table on the AgFiniti page fixed/translated as well: hidden link

Thank you!

September 11, 2024 at 1:38 am #16163912

Long Nguyen
WPML Supporter since 02/2022

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

You will need to click on the translation icon to update the translation and complete it, as I mentioned in step 3 above. When you see the pen icon that means the translation is completed.

Thanks.

Edit Page “SMS” ‹ Ag Leader — WordPress 2024-09-11 08-31-19.png