Skip Navigation

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

Problem:

Custom Code is not translatable.

Solution:

The code should be wrapped by the GetText function, then scan the theme/plugin via WPML-> Theme and Plugin Localization.

After that, the strings will be translatable in WPML-> String Translation.

Relevant Documentation:
https://wpml.org/documentation/support/translating-the-theme-you-created/

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 10 replies, has 2 voices.

Last updated by dvirH-2 1 year, 8 months ago.

Assisted by: Osama Mersal.

Author Posts
May 20, 2023 at 12:13 am #13681649

dvirH-2

Hi,

I need help with an issue related to the translation of some custom strings I've added to a WooCommerce registration form via my theme/plugin.

In my code, I've added a checkbox for Terms and Conditions, and I'd like to ensure these strings:

"I've read and accept the terms & conditions"
"Terms and condition are not checked!"
are translatable into other languages using WPML. Here's a snippet of the code I'm using:

// Add term and conditions check box on registration form
add_action( 'woocommerce_register_form', 'add_terms_and_conditions_to_registration', 20 );
function add_terms_and_conditions_to_registration() {

if ( wc_get_page_id( 'terms' ) > 0 && is_account_page() ) {
?>
<p class="form-row terms wc-terms-and-conditions">
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
<input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="terms" <?php checked( apply_filters( 'woocommerce_terms_is_checked_default', isset( $_POST['terms'] ) ), true ); ?> id="terms" /> <span><?php printf( __( 'I’ve read and accept the terms & conditions', 'woocommerce' ), esc_url( wc_get_page_permalink( 'terms' ) ) ); ?></span> <span class="required">*</span>
</label>
<input type="hidden" name="terms-field" value="1" />
</p>
<?php
}
}

// Validate required term and conditions check box
add_action( 'woocommerce_register_post', 'terms_and_conditions_validation', 20, 3 );
function terms_and_conditions_validation( $username, $email, $validation_errors ) {
if ( ! isset( $_POST['terms'] ) )
$validation_errors->add( 'terms_error', __( 'Terms and condition are not checked!', 'woocommerce' ) );

return $validation_errors;
}

Currently, I'm using 'woocommerce' as the text domain in my gettext calls. I've tried scanning for strings in WooCommerce using the String Translation tool in WPML and also checked the Admin Screen Strings, but these custom strings do not seem to appear there, probably because they might not be present in the WooCommerce's original text strings.

Can you guide me on how I can make these custom strings translatable? Do I need to create a separate .pot file for these strings and load it with my unique text domain? If so, how do I do that and make it work with WPML?

I appreciate any guidance or resources you can provide. Thank you in advance for your assistance.

Best regards,

May 21, 2023 at 9:51 am #13684187

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.

I'm afraid supporting custom code is out of our support scope, but please check this guide to help you fix the issue. (https://wpml.org/documentation/support/translating-the-theme-you-created/)

Also, please try the following steps to help you register the strings if the GetText call is done correctly.
1- Go to String Translation
2- Enable the "Auto-register strings for translation" option
3- Visit the front end, where you can see those strings
4- Search for the strings in String Translation

Best regards,
Osama

May 21, 2023 at 10:20 am #13684275

dvirH-2

Hi Osama,
thanks a lot for the answer.

I know the method you mentioned, but I can't scan this page while logged in because it's the site registration/login page.

Do you have a solution for this?

Thanks,

May 21, 2023 at 10:22 am #13684277

Osama Mersal
Supporter

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

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

Hi,

Please let me know where this code is added. Is it added to WooCommerce, your theme, or a custom plugin?

Best regards,
Osama

May 21, 2023 at 10:25 am #13684279

dvirH-2

I added this code to the function.php file throw dashboard - appearance - theme file editor.

May 21, 2023 at 10:26 am #13684281

Osama Mersal
Supporter

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

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

Hi,

Thanks for your update. Please scan your active theme via WPML-> Theme and Plugin Localization, and check if the strings will appear in String Translation.

Best regards,
Osama

May 21, 2023 at 8:21 pm #13685465

dvirH-2

Thanks Osama, I found the string as you said.

How i can add a link to the "Privacy Policy" page in Hebrew?
i was able only to set a link to the Terms & Conditions page.

קראתי והבנתי את תנאי השימוש באתר ואת מדיניות הגנת הפרטיות של החברה והם מקובלים עלי לרבות לגבי דיוור ישיר והזכות לבקש הסרה ממאגר זה.

This is the page, and its needs to hyperlink the words "מדיניות הגנת הפרטיות":

hidden link

Thank you

Screenshot 2023-05-21 at 14.17.09.png
May 22, 2023 at 6:47 am #13686461

Osama Mersal
Supporter

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

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

Hi,

If you can see the string in String Translation, please add the hyperlink in the translation field while translating the string.

If that is not the case, please share a screenshot of the string in String Translation.

Best regards,
Osama

May 22, 2023 at 7:54 am #13686807

dvirH-2

I found the string but I don't know how to add a hyperlink to a value I added to the string.
The original string contains a link to the site's terms and conditions, and I would like to add to the translation another link to the privacy policy (marked in the screenshot).
The link I want to add:
hidden link

Screenshot 2023-05-22 at 01.50.16.png
May 22, 2023 at 7:58 am #13686845

Osama Mersal
Supporter

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

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

Hi,

Please wrap the marked sentence between <a> tags. For example: