Skip Navigation

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

Problem: How to translate custom text from my theme

Solution: Wrap them around gettext functions as per WordPress standards. you can use the link below as an example of how it should look.

Relevant Documentation:
- https://wpml.org/forums/topic/translate-footer-of-my-site/#post-9861701
- https://developer.wordpress.org/themes/functionality/internationalization/

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.

Our next available supporter will start replying to tickets in about 7.84 hours from now. Thank you for your understanding.

This topic contains 23 replies, has 2 voices.

Last updated by herng-yueL 7 months ago.

Assigned support staff: Alejandro.

Author Posts
October 25, 2021 at 1:19 pm #9857571

herng-yueL

Thanks i willl look into that, can you please help me check why the footer is not translated as well?

October 25, 2021 at 1:22 pm #9857587

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

Hello,

we will only talk about the footer on this ticket.
Would you mind telling me how do you set the footer or modify its content in the original language? this hint will let me know what we can do about this issue.

Regards.

October 25, 2021 at 2:23 pm #9858233

herng-yueL

I have created another footer in our custom theme to overwrite the existing footer header, part of the code is shown here:

Capture.PNG
October 25, 2021 at 2:23 pm #9858257

herng-yueL

Here are also some of the details about this: https://wpml.org/forums/topic/product-variation-not-synced/

October 26, 2021 at 6:44 am #9861701

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

Ok, so the footer is a custom one. in that case make sure the gettext functions are correct. because i can see you are using https://developer.wordpress.org/reference/functions/esc_html_e/

however you're not adding the context which is something you want to add if you want to find your strings.

The code would end up looking like this:

$current_lang= apply_filters( 'wpml_current_language', NULL );
$localized_permalink= $wpml_permalink = apply_filters( 'wpml_permalink', '<em><u>hidden link</u></em>', $current_lang );

<li><a href=" <?php $localized_permalink ?> "><?php esc_html_e('string goes here', 'custom-footer') ?></li>

It uses 2 of our hooks to localize the permalink as well. you can learn about them here:

- https://wpml.org/wpml-hook/wpml_permalink/
- https://wpml.org/wpml-hook/wpml_current_language/

After you add the new code, you should re-scan the theme in WPML > Theme and plugin localization > Select your theme and scan it.

and then you will be able to translate the text in WPML > String translation

Please note:

- You have a custom footer so this is as far as we can go with custom coding it
- The code provided is meant to point you in the right direction, it might not work as-is or need a different code to make it work. its existant is just built to show you how you can use our hooks and integrate them in your code.

- Remember that custom coding and support for custom coded elements is out of the scope of our support.

- you can also try other get_text functions if this one doesn't work: https://developer.wordpress.org/themes/functionality/internationalization/

October 26, 2021 at 6:51 am #9861711

herng-yueL

No, please check the topic I have linked you to:
https://wpml.org/forums/topic/product-variation-not-synced/

I am able to find the text but after translating it, it does not work. When I switch to another language it doesn't change language.

October 26, 2021 at 8:56 am #9862709

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

Can you please add the domain to the localized escaped HTML function, and try again? without domains, it's possible you encounter issues due to duplicate strings.

at the same time, it's also very possible that instead of using esc_html_e you can use instead _e() and that will help in localizing the content correctly.

Please try it out and let me know how it goes.

October 26, 2021 at 9:24 am #9863039

herng-yueL

Tried with e_() and it doesn't make any difference.

For this code:

 
$current_lang= apply_filters( 'wpml_current_language', NULL );
$localized_permalink= $wpml_permalink = apply_filters( 'wpml_permalink', '<em><u>hidden link</u></em>', $current_lang );
 
<li><a href=" <?php $localized_permalink ?> "><?php esc_html_e('string goes here', 'custom-footer') ?></li>

Do I need to add for each and every of the _e() I use? Or only just the beginning?

Sorry, I don't know how this code works. You may also help me to test on the staging site that I sent you earlier and let me know if it works, thanks.

October 26, 2021 at 10:56 am #9863607

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

I wanted to test this on your site but i got 504 everytime 🙁

the WPML hooks from the 2 variables you mentioned in your last reply only needs to be added once before the localized text.

Once you do that, you need to scan your theme and the text should appear in WPML > String translations.

when i accessed this test site, however i didn't see any change from the original code you had sent on the screenshot (from one of the previous replies), did you remove what you did?

October 26, 2021 at 12:00 pm #9864075

herng-yueL

the screenshot I sent was on the main site, I did not do that on the test site yet, because when I scan, all text does appear and so I did not do this step.

Every text able to translate automatically but it just didnt show.

October 26, 2021 at 2:04 pm #9865297

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

i followed the same sueggestions i gave you above and it works without issues as seen here: hidden link

Could it be that you skipped something i followed, instead?

October 26, 2021 at 3:20 pm #9866117

herng-yueL

I have added to my main site like this:

However still not working, tried to check on the Privacy Policy text, still in english..

Capture.PNG
October 26, 2021 at 3:33 pm #9866295

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

1) Did you rescann the string and tried to translate it again from WPML > String translation?

2) as you could see before, it worked with both _e() and esc_html_e() in the staging site, so i suspect the problem could be on the server side.

3) Can you flush your cache if it exists?

4) If the problem remains, try enabling all the plugins you have installed, on the staging site and check if the translation disappears now.

October 26, 2021 at 3:47 pm #9866337

herng-yueL

Scanned the string, translated the string, flushed the cache, still the same.. Will try to add all the plugins in and update you about this. Thanks

October 27, 2021 at 9:35 am #9872309

herng-yueL

I have replicated all the plugins to the staging site, but it is working.. not sure why my main site is still not working..