Skip Navigation

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

Problem:
You are trying to manually translate a string using WPML, which translates correctly in all languages except Spanish. The translation only appears when 'Look for strings while pages are rendered' is enabled, reverting to the default when disabled.
Solution:
We suspect the issue might be due to two reasons:
1) The text domain might not be used or loaded correctly. Ensure your code includes the text domain like this:

__( 'Text to translate', 'your-text-domain' )

For more details on internationalization, visit WordPress Developer Internationalization.
2) The .mo files may need regeneration. You can regenerate these files by navigating to WPML → Support → Troubleshooting and clicking on "Show custom MO Files Pre-generation dialog box".

If this solution does not resolve your issue, or if it seems outdated or irrelevant to your case, 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 the problem persists, please open a new support ticket with us for further assistance.

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

Last updated by Andrey 2 months, 3 weeks ago.

Assisted by: Andrey.

Author Posts
November 28, 2024 at 1:27 pm #16455335

marcom-187

Background of the issue:
I'm trying to manually translate a string using WPML. This string gets correctly translated in all languages except for the Spanish language. If I enable the 'Look for strings while pages are rendered' and refresh the frontend, the string is correctly translated in Spanish. As soon as I disable 'Look for strings while pages are rendered', the default version is shown instead of the Spanish one. This happens only in the Spanish language.

Symptoms:
String translation is not working for the Spanish language unless 'Look for strings while pages are rendered' is enabled.

Questions:
How to fix the issue where the string translation is not working for the Spanish language?
Why does the string translation only work when 'Look for strings while pages are rendered' is enabled?

November 28, 2024 at 2:22 pm #16455703

Andrey
Supporter

Languages: English (English ) Russian (Русский )

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

While one of my teammates takes care of your ticket, I will provide you with the first debugging steps.

Could you please give us more detailed information on what the string is? Where does it come from?

I've enabled debug information for this support ticket. Please refer to this link for instructions on how to retrieve this information from your site and provide it to us: http://wpml.org/faq/provide-debug-information-faster-support/

November 28, 2024 at 2:31 pm #16455762

marcom-187

The string is added in function.php using __( 'Text to translate', 'text_to_translate' ) method.

Few days ago was working in all languages, now translation works for all languages except spanish.

There is not cache and broswer cache was purged. It's weird that If I enable the 'Look for strings while pages are rendered' and refresh the frontend, the string is correctly translated in Spanish. As soon as I disable 'Look for strings while pages are rendered', the default version is shown instead of the Spanish one.

November 28, 2024 at 2:51 pm #16456007

Andrey
Supporter

Languages: English (English ) Russian (Русский )

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

I suspect there are two reasons here:

1) You are not using the text domain, or it is not loaded. It should be:

__( 'Text to translate', 'your-text-domain' ) 

https://developer.wordpress.org/apis/internationalization/

2) You might need to regenerate the .mo files. You can do this by clicking the "Show custom MO Files Pre-generation dialog box" in WPML → Support → Troubleshooting.

November 28, 2024 at 3:28 pm #16456120

marcom-187

I did both steps, but same problem.
I tried also to delete the strings, add a different text domain, scan again the theme and translate again, but the spanish lang is not translating. All the other languages are fine.

I tried to repeat again your steps but nothing changed. How is possibile that only one language is showing the issue on that string? Other strings available in function.php work fine in spanish, just one is not working.

I tried also to clear WPML cache from the troubleshoot page, but no luck.

What to do now?

November 28, 2024 at 5:30 pm #16456584

marcom-187

Hi,

in the meanwhile that I'm still waiting for an answer, I did a check also in the database, and I confirm that the translation is correctly showing in the database. I was able to see that through the query:

SELECT
s.id,
s.context,
s.name,
t.language,
t.value AS translation_value
FROM wp_icl_strings s
JOIN wp_icl_string_translations t ON s.id = t.string_id
WHERE s.context LIKE 'nf_%';

In addition, as I said before, If I enable the 'Look for strings while pages are rendered' and refresh the frontend, the string is correctly translated in Spanish. As soon as I disable 'Look for strings while pages are rendered', the default version is shown instead of the Spanish one.

So, please, can you tell me what is going on here?

November 29, 2024 at 1:08 pm #16459693

Andrey
Supporter

Languages: English (English ) Russian (Русский )

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

Thank you for the updates. The translation should be sourced from the generated .mo files.

Could you also check the following workaround to confirm whether you are not experiencing the same issue?

https://wpml.org/errata/wordpress-6-7-mo-files-not-loaded-and-leading-to-missing-translations-on-front-end/

If the problem persists, I will need to request temporary access to your site (both wp-admin and FTP). Ideally, this should be a test site where the issue has been replicated, if possible. When you log in to leave your next reply, you'll find the necessary fields below the comment area. The information you provide will be private, meaning that only you and I will be able to see and access it.