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.
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?
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.
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.
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.
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?
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.