Skip Navigation

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

Problem:
The client has a Google review widget on their website, translated into four languages using different JavaScripts for each language. They face an issue where every time the page is updated, the JavaScripts for other languages revert to the main language, requiring manual adjustments each time.
Solution:
We recommend not using JavaScript code in the glossary as WPML does not support translating JavaScript natively. Instead, you can use WPML's filters and action hooks to manage multilingual support. Here's how you can proceed:
1. Remove the JavaScript code from the glossary.
2. Write custom code to detect the current language and insert the appropriate JavaScript code. You can find guidance on this through the following documentation links:

If you need professional help to implement this, consider hiring a WPML-certified contractor from this list.

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 3 replies, has 1 voice.

Last updated by Carlos Rojas 1 week, 3 days ago.

Assisted by: Carlos Rojas.

Author Posts
January 26, 2025 at 1:20 pm #16635211

Rob Kroos

Background of the issue:
I have a Google review widget on my website hidden link, which is translated into 4 languages. I use 4 different JavaScripts for the widget so the reviews are translated into the corresponding languages. I've put the JavaScripts in the glossary but that doesn't work.

Symptoms:
Every time I update the page on which the widget is published, the JavaScripts for the other languages get translated to the main language, requiring manual changes each time.

Questions:
How can I prevent the JavaScripts from being translated to the main language when I update the page?
Is there a way to automate the process so I don't have to manually change the JavaScripts every time?

January 27, 2025 at 6:57 am #16635943

Waqas Bin Hasan
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting the support. Meanwhile this ticket is attended by one of my colleagues, please note that support for JavaScript "code" in glossary and translations is not available and these can not be translated unlike other text.

However, WPML offers filters and action hooks that can be used in your WordPress theme or plugin to provide correct multilingual support. Browse following resources for more information:

- https://wpml.org/documentation/support/wpml-coding-api/
- https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/
- https://wpml.org/documentation/support/wpml-coding-api/shortcodes/
- https://wpml.org/faq/how-to-get-current-language-with-wpml/

The general idea is to write custom code to detect the current language and insert your desired JavaScript code accordingly.

Regards.

January 30, 2025 at 11:32 am #16651030

Rob Kroos

Based on the documentation you send me I couldn't find the solution.

January 30, 2025 at 12:59 pm #16651653

Carlos Rojas
Supporter

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

Timezone: Europe/Madrid (GMT+01:00)

Hello,
My name is Carlos and I will continue working on this ticket

I will rephrase my colleague's message and try to make it simpler to avoid a misunderstanding: WPML doesn't support the translation of Javascript natively, and using it in the Glossary is also not supported.

To solve this issue you have to options:
- Keep manually updating the Javascript on the translated pages when a change is done to the page in the original content (what you are doing now and trying to avoid)
- Create a custom code that manages this update for you following the links shared by my colleague. Keep in mind that these custom code solutions fall outside of the scope of our support service, however, there is a list of WPML-certified partners that you can contact to get a solution: https://wpml.org/contractors/

Thank you very much for your patience and understanding!
Best regards,
Carlos