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.

Tagged: 

This topic contains 1 reply, has 0 voices.

Last updated by Mihai Apetrei 3 days, 2 hours ago.

Assisted by: Mihai Apetrei.

Author Posts
January 23, 2025 at 1:34 pm #16628144

milcoP

Background of the issue:
I am trying to translate text from a custom JavaScript on my website hidden link.
it is used on this page: hidden link

Symptoms:
No specific issue or error message mentioned.

Questions:
How can I translate a custom JavaScript?

January 23, 2025 at 1:44 pm #16628264

Mihai Apetrei
Supporter

Languages: English (English )

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

Hi there.

Unfortunately, it is impossible to translate these strings with String Translation because they are added through JavaScript and not localized.

WordPress currently only offers a localization API in PHP, not directly in JavaScript. To fix this and make the text translatable, you can use the "wp_localize_script" function: https://developer.wordpress.org/reference/functions/wp_localize_script/

For more details, please check the reply from my colleague here: https://wpml.org/forums/topic/string-translation-138/#post-9698875

Kindly note that custom programming work is beyond our scope of support. If the above suggestions didn't help or you're unsure about how to achieve it, we suggest contacting one of our 3rd party contractors that specialize in custom work with WPML
https://wpml.org/contractors/

I hope that you will find this answer helpful.

Mihai