Skip Navigation

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

Problem:
The client is unable to translate the cookies notice on their website after modifying the text, and the provided WPML documentation did not resolve their issue.
Solution:
We recommend updating the gettext code in your theme or plugin files to ensure proper translation string and text domain usage. Here are the steps:
1. Update your gettext code to include the correct text domain and ensure the URL is wrapped appropriately for translation. For example:

<div class="message"><br />    <?php echo sprintf(<br />        esc_html__( 'We use cookies to improve your user experience. %s', 'your-text-domain' ),<br />        '<u><b><a href="https://mp-performance.ae/privacy-policy">' . esc_html__( 'Learn more', 'your-text-domain' ) . '</a></b></u>' <br />    ); ?><br />

2. Scan the theme or plugins for strings using WPML's String Translation.
3. Translate the strings as needed in WPML.

If this solution does not apply to your case, or if it seems outdated, 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 issues persist, 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.

Tagged: 

This topic contains 0 replies, has 0 voices.

Last updated by omarA-71 5 days, 13 hours ago.

Assisted by: Lauren.

Author Posts
February 3, 2025 at 6:46 pm #16664083

omarA-71

Background of the issue:
I am trying to translate the cookies notice on my website. The issue can be seen on this page: hidden link.

I reached Elessi theme makers. Here:

hidden link

Theme maker appointed me to contact WPML.

I did contact WPML. I've been told to follow a document

hidden link

which doesn't apply on my case...

The file originally was translateable. But as we changed the file text, to make it look good. It's different now and cannot be translated.

The documentation staff member of WPML doesn't work, they kept insisting I should follow the document. It didn't help. Then the staff got disconnected leaving me with no help.

I want this to be support ticket!. Not a chat. Speak with someone professional Please.

Symptoms:
I expected to see the string translation, but instead, I got nothing.

Questions:
Why can't I see the translation for the cookies notice?
How can I resolve the issue of the missing translation?

February 3, 2025 at 6:56 pm #16664099

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-05:00)

Please make sure you scan the theme after you add the gettext call to the string, then you should be able to find it in string translation and add the strings.

February 3, 2025 at 6:58 pm #16664100

omarA-71

I tried to apply gettext on the desired string to be translated. Whatever I added didn't get translated to echo of PHP file. Instead of printed the actual gettext text on the page.

Please note this is the php file: hidden link

If you need theme file and custom file to apply it to your sandbox. Please let me know. But I'm informing you it doesn't work.

Also the instructions are for pure PHP file, not for wordpress theme files where it starts as PHP file but most of the content are pure html code.

February 3, 2025 at 7:33 pm #16664265

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-05:00)

The gettext code for your content should look something like this:

<div class="message">
    <?php echo sprintf( 
        esc_html__( 'We use cookies to improve your user experience. %s', 'your-text-domain' ), 
        '<u><b><a href="<em><u>hidden link</u></em>">' . esc_html__( 'Learn more', 'your-text-domain' ) . '</a></b></u>' 
    ); ?

Please update your file accordingly, scan the theme/plugins for strings and then translate using String Translation.

February 4, 2025 at 6:55 am #16664989

omarA-71

(Learn More) is not translated. Please check the website and this code:

<?php echo sprintf(
esc_html__( 'We use cookies to improve your user experience. %s', 'hidden link' ),
'<u><b>hidden link">' . esc_html__( 'Learn more', '/privacy-policy/' ) . '</b></u>'
); ?>

February 4, 2025 at 4:21 pm #16667862

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-05:00)

Your gettext usage is incorrect because esc_html__() expects a translation string and a text domain, but you have provided a URL instead of a text domain. Try adjusting your code using something similar to this:

<?php echo sprintf(
    esc_html__( 'We use cookies to improve your user experience. %s', 'your-text-domain' ),
    '<u><b><a href="<em><u>hidden link</u></em>">' . esc_html__( 'Learn more', 'your-text-domain' ) . '</a></b></u>'
); ?>

The second parameter of esc_html__() should be your actual theme or plugin text domain (e.g., 'your-text-domain').

February 4, 2025 at 4:52 pm #16667964

omarA-71

Understood.

But now the https link doesn't point to the arabic version. How do I force it when the language shown in main page as arabic?

February 4, 2025 at 8:31 pm #16668457

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-05:00)

You can also wrap the URL in a gettext call and then translate the URL using WPML String Translation. It would look something like this:

<?php echo sprintf(
    esc_html__( 'We use cookies to improve your user experience. %s', 'your-text-domain' ),
    '<u><b><a href="' . esc_url( __( '<em><u>hidden link</u></em>', 'your-text-domain' ) ) . '">' . esc_html__( 'Learn more', 'your-text-domain' ) . '</a></b></u>'
); ?>

Please note these are examples that you can use to create your own custom code. I can't garauntee that they work exactly as is, but it should help point you in the right direction.

February 6, 2025 at 8:04 am #16673819

omarA-71

Thank you!