This thread is resolved. Here is a description of the problem and solution.
Problem:
String Translation - domain is missing from the list when using HAML
Solution:
The 4.0.7 version is an older version and since then there have been plenty of changes made to our code.
As WPML itself does not scan or officially support HAML files I wouldn't be able to point out what change was made that could have caused this behavior with HAML files.
One of the functions that scan the templates has changed. It's possible the new function does not scan non-PHP files
Line 31 of wpml-string-translation\classes\strings-scanning\wpml-st-theme-plugin-scan-dir-ajax.php will allow .haml files to be scanned by changing:
$file_type = array( 'php', 'inc' );
to
$file_type = array( 'php', 'inc', 'haml' );
However, I tried this and it doesn't catch the strings in Haml.
You might want to examine the following file which should be where all the actual processing is happening:
wpml-string-translation\inc\potx.php
NOTE: I did test with version 4.0.7 of WPML and its version at the time of String Translation and it still does not scan HAML files.
Once you go to WPML->Themes and Plugins localization-> Scan your theme and then you get a list of all the files scanned, only .php files are scanned.
My suggestion would be to create a .mo file with your strings
https://wordpress.stackexchange.com/questions/127917/generating-po-mo-translating-files-from-scratch-in-a-wordpress-theme
Relevant Documentation:
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.
This topic contains 10 replies, has 2 voices.
Last updated by Jeremy 4 years, 8 months ago.
Assisted by: Bobby.
Author | Posts |
---|---|
February 21, 2020 at 10:50 pm #5544289 | |
Jeremy |
I am trying to get certain translation strings to appear, so we're using this for example: echo __('Practice Areas', 'bogoroch'); We went to the String Translation settings page and enabled "Look for strings while pages are rendered" Refreshed the homepage (Which is where the String is) But the 'bogoroch' domain won't even appear under " Select strings within domain" dropdown. Help |
February 22, 2020 at 12:01 am #5544397 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
Hi There, As a test please go to WPML->Theme and Plugins localization. Within there you should be able to find your domain, select it and scan it. After the scan finishes go to String translation and let me know if you can find it. |
February 24, 2020 at 3:28 pm #5555699 | |
Jeremy |
We found the Theme under "Strings in the themes", selected the theme and ran a scan, but it didn't seem to work. We suspect it's because we're using HAML templates, so our front-page.html looks like this: <?php get_header(); $haml = new MtHaml\Environment('php'); $template = __DIR__ . 'https://cdn.wpml.org/haml-templates/front-page.haml'; get_footer(); ?> And then the strings are located within /haml-templates/front-page.haml for example: = __('Contact us today', 'bogoroch') We previously used an older version of WPML (4.0.7) with another project of ours that uses HAML templates and we didn't have an issue getting the translation strings to appear within WPML. |
February 24, 2020 at 5:37 pm #5556865 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
I believe that as long as you are using the Gettext call in an HTML file and not a HAML file then it should work as expected. Change your text-domain temporary for one string from bogoroch to 'bogoroch-test' and save it and then go back to WPML->Themes and Plugins localization and see if the new text-domain populates under the theme Let me know your results, please. |
February 24, 2020 at 8:49 pm #5557439 | |
Jeremy |
Sorry, by HTML I meant PHP file. Our PHP Files are loading HAML templates, and our translation strings are defined within HAML files and NOT PHP. For example, here is how we're loading HAML template for the Homepage's front-page.php: <?php get_header(); $haml = new MtHaml\Environment('php'); $template = __DIR__ . 'https://cdn.wpml.org/haml-templates/front-page.haml'; get_footer(); ?> And then the front-page.haml has the translation strings. example: .section-video#playButton Once again, this setup worked just fine with the older WPML version 4.0.7, but it doesn't seem to be working any longer with the latest WPML. Is there a workaround? |
February 24, 2020 at 9:31 pm #5557551 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
I personally do not see why this wouldn't work. Were you able to test changing the text-domain? This will allow you to see if a specific string is getting picked up. Please note that we currently are not able to provide support for custom work within this forum. I will, however, like to take a closer look and see if something is missing and why its not getting picked up. I would like to request temporary access (wp-admin and FTP) to your site to test the issue. **Before we proceed I recommend taking FULL BACKUP of your database and your website.** You will find the needed fields for this below the comment area when you log in to leave your next reply. NOTE: If access to the live site is not possible and the staging site does not exist please provide me with a duplicator package created with the duplicator plugin. Thank you, |
February 25, 2020 at 7:55 pm #5565695 | |
Jeremy |
Hi, |
February 25, 2020 at 8:19 pm #5565789 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
Thank you for the access details! Go to WPML->String translation->Filter by strings within the domain "text-domain" or "bogroch" and click on the View. You will notice that all these strings that have been picked up by String Translation are coming from pure PHP files such as functions.php or /custom-post-type.php for example. This is because any getText call function called within the HAML file does not seem to work. ----------------- As noted in my previous thread being that you are using a custom theme and custom code we are not able to provide support for custom work within this forum, but I have inquired our developers regarding HAML and WPML, and will update you once I have their response. |
February 25, 2020 at 8:42 pm #5565813 | |
Jeremy |
Great thank you. Also, once again, keep in mind that we were using haml templates with WPML 4.0.7 and we didn't have this issue. |
February 26, 2020 at 6:33 pm #5573763 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
Hi There, The 4.0.7 version is an older version and since then there have been plenty of changes made to our code. As WPML itself does not scan or officially support HAML files I wouldn't be able to point out what change was made that could have caused this behavior with HAML files. One of the functions that scan the templates has changed. It's possible the new function does not scan non-PHP files Line 31 of wpml-string-translation\classes\strings-scanning\wpml-st-theme-plugin-scan-dir-ajax.php will allow .haml files to be scanned by changing: $file_type = array( 'php', 'inc' ); to $file_type = array( 'php', 'inc', 'haml' ); However, I tried this and it doesn't catch the strings in Haml. You might want to examine the following file which should be where all the actual processing is happening: NOTE: I did test with version 4.0.7 of WPML and its version at the time of String Translation and it still does not scan HAML files. Once you go to WPML->Themes and Plugins localization-> Scan your theme and then you get a list of all the files scanned, only .php files are scanned. My suggestion would be to create a .mo file with your strings |
March 9, 2020 at 2:19 pm #5648347 | |
Jeremy |
Thanks for pointing out an alternative solution. This works. Thanks! |