This thread is resolved. Here is a description of the problem and solution.
Problem:
The client has translations in .po/.mo files within the languages directory of their child theme and wants WPML to use these translations instead of its own.
Solution:
We recommended ensuring that the translation file names match the language locale. The client can verify the language locale by navigating to WPML >> Languages >> Edit Languages. We provided a link to the WordPress developer documentation for further guidance on using
load_child_theme_textdomain
:
https://developer.wordpress.org/reference/functions/load_child_theme_textdomain/
If the solution provided here does not apply or is outdated, we suggest opening a new support ticket. We also 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. For further assistance, please contact us through the WPML support forum: https://wpml.org/forums/forum/english-support/.
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: Exception
This topic contains 18 replies, has 2 voices.
Last updated by Noman 8 months, 1 week ago.
Assisted by: Noman.
Author | Posts |
---|---|
March 12, 2024 at 8:40 am #15398088 | |
dariod-33 |
I have a serious problem. I created a page in English that uses a custom profile. One of my collaborators modified the page in Italian with Elementor, effectively creating a different page. I want to delete the Italian page and use the English one with the translation done by WPML, but if I delete the Italian page, it doesn't display it even though I have translated all the strings with the advanced editor. If I restore it, it still keeps the two pages misaligned. I want to reset all the translated versions so that they only use WPML. How can I do this? |
March 12, 2024 at 9:03 am #15398133 | |
dariod-33 |
OK; it partially worked. That is some text are in Italian and in English, but NOT the text that are in the Page Template and that use as requested __() and _e() for loading texts in text domain. Note that text domain works fine for all other pages. It looks like the WPML is loading the tempale as in English even if other languages are used. |
March 12, 2024 at 9:22 am #15398191 | |
dariod-33 |
There are several things I don't understand about the coexistence between WPML and the .po files for my child theme and the parent theme. Q1. Does WPML use the text domain of the child theme for both pages and, more importantly, templates? |
March 12, 2024 at 9:26 am #15398203 | |
Noman Supporter
Languages: English (English ) Timezone: Asia/Karachi (GMT+05:00) |
Glad to hear it partially worked. For translating the hardcoded strings, please follow the below steps: 1. Please make sure the strings from PHP templates are wrapped in the gettext(__()) function by following this doc: https://wpml.org/documentation/support/translating-the-theme-you-created/ 2. Scan the parent/child theme from WPML >> Theme and plugins localization page. 3. Go to WPML >> String Translation, search for these strings, and add the translation. 4. If the above steps don’t help, please try the below procedures: 4.1. Go to the WPML >> String Translation page and in the Auto register strings for translation section, enable the ‘Look for strings while pages are rendered’ option. Here is a doc for more details: Please let me know the results, |
March 12, 2024 at 9:30 am #15398229 | |
dariod-33 |
I already use __("....", 'astra-child') and _e(...) / _n(...) in all my theme and I ALREADY have all those strings translated in all languages in .po /.mo files in languages subdirectory of my theme. I do NOT WANT that WPML translates those strings but it should use my translation file. |
March 12, 2024 at 9:32 am #15398249 | |
dariod-33 |
PS My child theme already load its text-domain as well as the parent theme load its text-domain in they functions.php. WPML should simple let WordPress to use those strings. |
March 12, 2024 at 10:21 am #15398503 | |
dariod-33 |
It looks like WPML ignores the fact that in a page template I already have translatble strings as such: ``` and in .po file I have ``` |
March 12, 2024 at 10:28 am #15398544 | |
dariod-33 |
Note that in my functions.php I already have $done = load_child_theme_textdomain('astra-child', get_stylesheet_directory() . '/languages'); and I have both it.po/.mo in languages subdirectory of my child theme. |
March 12, 2024 at 10:31 am #15398586 | |
dariod-33 |
I was wondering if in WPML->Settings->Custom Fields Translation is there any custom field that I can change to tell WPML "hey, please, use my text domain for template pages for translation of strings in PHP code" |
March 12, 2024 at 11:28 am #15399034 | |
Noman Supporter
Languages: English (English ) Timezone: Asia/Karachi (GMT+05:00) |
Could you please try to follow the below steps to see if they resolve the issue: 1. Please go to WPML >> Theme and Plugins localization page. If the above steps don’t help, you should be able to import the theme/plugin translation from WPML >> String Translation > Import / Export .po file section as you can see in the attached screenshot. Here is a doc for more details: Thank you |
March 12, 2024 at 11:41 am #15399199 | |
dariod-33 |
Done, but it did not work. IMporting is not a great option because I continuosly update .po files. I do not want to import po files every time I change even a single string. I simply want that po files are honred. Furthermore, in this way I can specify only astra-child. What's about the parent theme? That is "astra"? |
March 12, 2024 at 12:58 pm #15399501 | |
Noman Supporter
Languages: English (English ) Timezone: Asia/Karachi (GMT+05:00) |
Okay, I’ve tried the same steps on a fresh WP site with the Astra theme and it seems to be loading the correct translation as you can see in the below posts: Default language post: Translated language post: Here is an Autologin URL of the fresh WP site: Could you please try to replicate the issue here and let me know how it goes? Thank you |
March 12, 2024 at 1:28 pm #15399592 | |
dariod-33 |
Thank you for cereating a sandbox. Good news: I was able to reproduce the problem. hidden link You will see a profile page. All the texts in that page are hardcoded in the profile template page. Of course I used gettext functions like __("text", 'astra-child') and of course I load the text domain and you can find the corresponding Italian and Chinese PO files in languages subdirectory of child theme. If you switch language, the menu is changed but all texts inside the page are still in English. They should switch to aItalian or Chinese. Of course, I do not want to load those texts in WPML database, but keep them in child theme PO file and I do not want to IMPORT PO files because they continuosly change while I am developing the theme. I hope this will help you to troubleshoot the problem. |
March 13, 2024 at 6:47 am #15402109 | |
Noman Supporter
Languages: English (English ) Timezone: Asia/Karachi (GMT+05:00) |
Thanks for replicating the issue at the fresh WP site. 1. I went to WPML >> Theme and plugins localization page and noticed that the astra-child theme domain has not been added yet in the “Enter textdomain” field as you can see in the attached screenshot. 2. I’ve tried to search frontend strings in child theme files and it seems they are not wrapped in the gettext function as you can see in the attached screenshot. 3. I’ve downloaded it.po file from the child theme and tried to search these highlighted strings and it seems they have not been added yet in that file. Could you please try to fix these issues or please let me know if I missed something? Thank you for your cooperation |
March 13, 2024 at 8:31 am #15402444 | |
dariod-33 |
That was the old version of file. I do not know why it was still there. Anyway, I fixed it and now all strings are wrapped by gettext functions. It does NOT work yet. I also changed astra to astra-child in theme customizing options. I added anothe page based on Model Template but it does not show anything. I was wondering if there is any rule in your sandbox preventing PHP to load JSON files. |