Skip Navigation

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

Problem:
You are working on a site under development and need to translate static content in PHP files and error messages in JavaScript.
Solution:
For translating static content in PHP files, we recommend using WPML's String Translation. Ensure that the text within your PHP files is wrapped in WordPress localization functions like

__()

or

_e()

. This allows WPML to recognize these strings and enables translation directly from the WordPress dashboard. For a step-by-step guide, please visit: https://wpml.org/documentation/support/enabling-text-translation-for-themes-not-compatible-with-wpml/

For translating error messages in JavaScript, utilize WPML's JavaScript Translation capabilities. Ensure your scripts are set up to work with WPML's string translation by registering your JavaScript strings with WPML. For more details, check out these resources:

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 you still need assistance, please open a new support ticket at WPML support forum.

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 2 voices.

Last updated by Mihai Apetrei 6 months, 1 week ago.

Assisted by: Mihai Apetrei.

Author Posts
October 15, 2024 at 8:11 pm #16292570

marcoH-26

Background of the issue:
I am working on a site under development and want to translate text that is not in the CMS but inside the code, such as static content in PHP files. This includes forms placeholders and error messages from JS codes.

Symptoms:
I don't understand the question about following documentation.

Questions:
How can I translate static content in PHP files using WPML?
Is there a way to handle translations for error messages in JS codes with WPML?

October 15, 2024 at 9:52 pm #16292698

Mihai Apetrei
WPML Supporter since 03/2018

Languages: English (English )

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

Hi there,

Thank you for reaching out and sharing the details of your project.

Translating static content within PHP files and handling error messages in JavaScript can indeed be a bit tricky, but we're happy to help you navigate through it smoothly.

For translating static content in PHP files, WPML offers a powerful feature called String Translation. By ensuring that the text within your PHP files is wrapped in WordPress localization functions like `__()` or `_e()`, WPML can recognize these strings and allow us to translate them directly from the WordPress dashboard. This approach helps manage translations efficiently without altering your core files.

Here’s a quick guide to get you started:
https://wpml.org/documentation/support/enabling-text-translation-for-themes-not-compatible-with-wpml/

When it comes to translating error messages within JavaScript code, WPML can handle these as well, but it requires a slightly different approach. We can utilize WPML’s JavaScript Translation capabilities by ensuring that your scripts are properly set up to work with WPML’s string translation. This involves registering your JavaScript strings with WPML so they can be translated just like any other string on your site.

For a detailed walkthrough, please take a look over this existing ticket here:

https://wpml.org/forums/topic/how-to-translate-javascript-strings/#post-13131375

and over the answer marked as a solution here:

https://stackoverflow.com/questions/66437622/how-can-i-translate-html-text-that-in-javascript-using-wpml

I hope that you will find all this information helpful.

Mihai Apetrei