- I have a website with the latest version of WordPress.
- A custom theme used there which contains TWIG files.
- I am localizing the website using latest version of WPML.
My procedure to localize the TWIG content is as follows:
1. I have converted all strings in TWIG files into constants, such as:
title: __('Bezpečné transakční zprávy', 'twigcon'),
desc: __('Posílejte zabezpečené transakční e‑maily, zprávy SMS, PUSH oznámení, nebo třeba dopisy.', 'twigcon')|raw,
etc.
2. To show the strings in WPML, I go to WPML/String Translation and enable the "Look for strings while pages are rendered" option.
3. I render the pages, go back to the settings and export the discovered strings to a .po file.
4. I translate the .po file and import it back with new translations. The translations are successfully visible in WPML under the correct domain (twigcon in my case).
The problem:
When I load the website, some strings on the page appear translated and some remain in the original language. I have noticed that the problem is with strings that contain HTML entities.
When a constant in TWIG file contains a HTML entity, such as non-breaking hyphen (‑), non-breaking space, etc. WPML does not display its translation on the website, even though it exists in WPML database.
I have tried applying raw or escape_html filters to constants in TWIG files, but the results were the same. Nevertheless, if I delete the problematic string, rescan the website, and add the translation for that string manually from within WPML, it shows on the website correctly.
Can you please advise on how to make this work without any workarounds? I.e., export/import.
Can you also confirm that this is the correct procedure to localize the strings from the TWIG files?
What is the link to your site? hidden link
(currently under a password, which I would prefer to not share publicly in a forum)
my apologies, the SSL was not working properly, please try again now.
There are only three TWIG strings and they are on the following page:
hidden link
These strings (constants) are available in the theme within index.twig under "twigcon" domain and they were correctly recognized by WPML when I enabled "Look for strings while pages are rendered".
You can see the excerpt of these constants from the index.twig here: hidden link
I then exported the strings under this domain (twigcon) as .po file, added translations, and imported it back. See the exported .po file with translations here, if needed: hidden link
Each translation starts with "Sample translation:" prefix to easily recognize whether the text has been switched or not.
Now, when you switch the language on the site to Slovak, you can see that the first string switches fine (this string does not contain any html entities), but the other two strings remain in original Czech language, likely because of the html entities used in them.
since there has not been any update since December, 2023 and the issue still persists, can you please let me know if there is a plan to resolve this anytime soon? Unfortunately, manually updating individual strings is not a workaround we could employ.
I am afraid this will take some time before we have a version with a permanent fix, currently, the fix is scheduled for WPML 4.7.
The best I can do i update you when the fix is released, and hopefully it will be sometime soon.
Hope you understand.
Regards,
Drazen
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.