This thread is resolved. Here is a description of the problem and solution.
Problem:
The client was unable to see the translated string for a custom plugin named 'growytasty' on the frontend, despite having scanned for strings and translated them in WPML.
Solution:
We discovered that the issue was related to the text domain not being loaded correctly. To resolve this, we added the following code to the 'growytasty.php' file to ensure the text domain is loaded:
function growytasty_load_textdomain() {<br /> load_plugin_textdomain('growytasty', false, dirname(plugin_basename(__FILE__)) . '/languages');<br />}<br />add_action('plugins_loaded', 'growytasty_load_textdomain');
After adding this code, the text domain loaded properly, and the translation appeared correctly on the frontend.
For more details on configuring and loading translation files, you can visit our documentation: Translating the Theme You Created.
If this solution does not apply to your case, or if it seems outdated, we recommend opening a new support ticket. Also, check related known issues at https://wpml.org/known-issues/, verify the version of the permanent fix, and confirm that you have installed the latest versions of themes and plugins. For further assistance, please visit our support forum at WPML Support Forum.
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: Custom Work, Exception
This topic contains 9 replies, has 3 voices.
Last updated by Bobby 2 months, 3 weeks ago.
Assisted by: Bobby.
Author | Posts |
---|---|
August 29, 2024 at 11:15 am #16119480 | |
benjaminK-50 |
Background of the issue: Symptoms: Questions: |
August 29, 2024 at 11:23 am #16119600 | |
Mihai Apetrei Supporter
Languages: English (English ) Timezone: Europe/Bucharest (GMT+02:00) |
Hi there. Can you please also share the code part where that string is added? Also, can you please let me know if you had the chance to also try to remove all the local/server/CDN caching, too? I can see that you also have a caching plugin active so please try to clear all the caching, too. Please let me know how things go. Mihai |
August 29, 2024 at 11:42 am #16119734 | |
benjaminK-50 |
Hi Mihai, Cache isn't the issue since the issue is on my local / dev site as well. I wrote down the steps i followed on the initial form but it removed it. I have cleared cache too. if ( ! empty( $producers ) && is_array( $producers ) ) { |
August 29, 2024 at 11:43 am #16119737 | |
benjaminK-50 |
You can see issue in hidden link |
August 30, 2024 at 12:53 am #16122576 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
Hi there, When I visit the link you shared with me I do not see as string named "Producer", am I missing it somehow? |
August 30, 2024 at 6:42 am #16122955 | |
benjaminK-50 |
Please see the screenshot - it's right below the product. |
August 30, 2024 at 11:29 pm #16126771 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
I would like to request temporary access (wp-admin and FTP) to your site to test the issue. **Before we proceed It is necessary to take FULL BACKUP of your database and your website. Providing us with access, you agree that a backup has been taken ** I often use the Duplicator plugin for this purpose: http://wordpress.org/plugins/duplicator/ 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, |
September 5, 2024 at 10:16 pm #16146926 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
Thank you for the access details! The string where is it added in the code? Also, the additional information string where is that one being pulled from as it is being translated OK but cannot locate it in String Translation. |
September 6, 2024 at 6:50 am #16147350 | |
benjaminK-50 |
The code in question is on : Line number 78 We are aware additional information is translating. |
September 6, 2024 at 6:39 pm #16150199 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
Thank you, I was able to locate it. You are not directly outputting the "Producer" string in your code. Instead, you are passing it to WooCommerce via the $tabs['producer']['title'] array entry, and WooCommerce handles rendering it on the product page. I did a quick test to make sure it is being picked up correctly by adding "test" in front of it, this worked and it displayed in the front end as well as being picked up by String Translation. So far we know that the string is being picked up in the front end as well as String Translation. since this string is not being translated properly, the issue is likely related to the text domain not being loaded. To verify I added this code in growytasy.php and reloaded the front end at the footer. add_action( 'wp_footer', function() { // This will output whether the text domain is loaded correctly if ( is_textdomain_loaded( 'growytasty' ) ) { echo '<p>Text domain growytasty is loaded.</p>'; } else { echo '<p>Text domain growytasty is NOT loaded.</p>'; } }); ( I have removed now since after registering the text domain verified that it is being loaded) The results are that the textdomain is not being loaded properly, which also explains why the .mo/.po files are missing from the plugin. To load the text domain I added the following code in growytasy.php function growytasty_load_textdomain() { // Adjust the path to the 'languages' folder if needed load_plugin_textdomain( 'growytasty', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); } add_action( 'plugins_loaded', 'growytasty_load_textdomain' ); The translation is working OK now and the text domain is loaded properly. Related Documentation: Our support policy does not cover custom themes and plugins. The provided code is for your use at your own risk, and WPML does not maintain it. Always back up your site before making any changes recommended by us or others. |
September 9, 2024 at 7:48 am #16154243 | |
benjaminK-50 |
Hi Bobby, Thank you so much for your help. |