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

Last updated by Bobby 5 months, 3 weeks ago.

Assisted by: Bobby.

Author Posts
August 29, 2024 at 11:20 am #16119517

john-robinA

Background of the issue:
Our website is a custom theme from scratch. I'm trying to translate the HTML texts in our website but it is not showing on string translation and translation management. Same with the custom checkout form using WooCommerce. I have been following these documentations: https://wpml.org/documentation/getting-started-guide/string-translation/how-to-translate-theme-options/, https://wpml.org/documentation/getting-started-guide/string-translation/, https://wpml.org/documentation/support/translating-the-theme-you-created/

Symptoms:
Cannot translate custom HTML texts and added checkout form in WooCommerce; they are not appearing in string translation and translation management.

Questions:
Can you guide me on what to do to translate the HTML texts and checkout form in WooCommerce in our custom theme?

August 29, 2024 at 2:37 pm #16120660

john-robinA

I asked this question in a group and one of them says that I should wrap my texts inside esc_html_e() function.

<?php esc_html_e('This string needs to be translated', 'your-domain'); ?>

so meaning, if I have to translate this text:
<h1>Arabian Expeditions & <br> Gastronomic Journeys</h1>

Should I put it like this?

<h1>
<?php esc_html_e('Arabian Expeditions & <br> Gastronomic Journeys', 'your-domain'); ?>
</h1>

and then create a function in functions.php?

August 29, 2024 at 6:36 pm #16121671

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-08:00)

Hi there,

There is no need to create a function in functions.php, simply locate where you have added the custom HTML in the code and replace it with this

<h1><?php echo esc_html__('Arabian Expeditions & 
 Gastronomic Journeys', 'your-text-domain'); ?></h1>

NOTE: make sure to change the 'your-text-domain' to the one for your theme.

Hint-- you can go to WPML->Themes and plugins localization and see the text domain the other strings under your theme are pulled in with, usually it's the theme name

To make this work you are wrapping your string in a gettext call (See documentation). Once that is done head to Themes and Plugins localization and re scan your theme for strings, you should be able to see the string now.

Let me know your results, please.

September 5, 2024 at 6:32 am #16143196

john-robinA

Hello! Thank you. The custom HTMLs are now being translated.

However, the issue still remains on the WooCommerce custom checkout form. WPML still can't read the added checkout fields. Can you please help me on this?

Thanks in advance!

dnd-woo-checkout-form.png
dnd-arab-checkout.png
September 5, 2024 at 8:50 pm #16146856

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-08:00)

Glad to hear that worked!

For the WC custom checkout fields, which plugin are you currently using to add them?

September 6, 2024 at 3:46 am #16147111
john-robinA

Hi! I used the Checkout Field Editor for WooCommerce plugin.

I already followed this documentation: https://wpml.org/forums/topic/checkout-field-editor-for-woocommerce-with-wpml/

However, my added fields still don't appear in the string translation. Can you help me locate the missing texts?

New threads created by Bobby and linked to this one are listed below:

https://wpml.org/forums/topic/split-translate-strings-from-checkout-field-editor-for-woocommerce-plugin/

cfe-wc-dnd-3.png
cfe-wc-dnd-2.png
cfe-wc-dnd.png
September 6, 2024 at 5:38 pm #16150025

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-08:00)

Of course, I'd be happy to help.

We try to keep each ticket to 1 issue, as we have resolved the original issue of registering custom HTML for translation, I will mark this thread as resolved and split the new issue with the Checkout Field Editor for WooCommerce plugin into its own thread.