Skip Navigation

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.

This topic contains 9 replies, has 3 voices.

Last updated by Bobby 2 weeks ago.

Assisted by: Bobby.

Author Posts
August 29, 2024 at 11:15 am #16119480

benjaminK-50

Background of the issue:
I am trying to use string translation for a Bespoke/Custom Plugin in WPML. I have added the plugin, specified the text domain, scanned for translatable strings in Theme and String Localization, and translated the strings in String Translation.

Symptoms:
On the frontend, the string was not translated. I have tried deactivating unnecessary plugins and changing the theme, but the issue persists.

Questions:
Why is the string translation not working on the frontend?
Are there any additional steps required for translating strings in a custom plugin?

August 29, 2024 at 11:23 am #16119600

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03: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.
1) Go to theme and plugin localizations
2) Find the plugin "growytasty" and scan for strings
3) Once strings found ( 17 were found ) then i translated it ( text domain - growytasty )

I have cleared cache too.

if ( ! empty( $producers ) && is_array( $producers ) ) {
$tabs['producer'] = array(
'title' => __( 'Producer', 'growytasty' ),
'priority' => 50,
'callback' => [ $this, 'producer_product_tab_content' ],
);
}

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-07: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.
In the product tabs section. The tab header itself is the issue.

Screenshot 2024-08-30 at 12.24.18 PM.png
August 30, 2024 at 11:29 pm #16126771

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

I would like to request temporary access (wp-admin and FTP) to your site to test the issue.
(preferably to a test site where the problem has been replicated if possible)

**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/
You will find the needed fields for this below the comment area when you log in to leave your next reply.
The information you enter is private which means only you and I have access to it.

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,
Bobby

September 5, 2024 at 10:16 pm #16146926

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07: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 :
/wp-content/plugins/growytasty/includes/Producer.php

Line number 78
Method: producer_product_tab

We are aware additional information is translating.
The one that's not translating is the "producer" string.

September 6, 2024 at 6:39 pm #16150199

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07: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:
https://wpml.org/documentation/support/translating-the-theme-you-created/#configure-and-load-translation-files-in-wordpress

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.

Screen Shot 2024-09-06 at 11.24.29 AM.png
Screen Shot 2024-09-06 at 11.06.41 AM.png
September 9, 2024 at 7:48 am #16154243

benjaminK-50

Hi Bobby,

Thank you so much for your help.
The issue has been resolved.

benjaminK-50 confirmed that the issue was resolved on 2024-09-09 07:48:04.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.