Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client was unable to translate strings within custom code snippets using WPML, despite using the text domain method.
Solution:
1. We advised the client to ensure that the code is written with internationalization in mind, specifically that the echo statements contain the correct format. For more details, see https://developer.wordpress.org/themes/functionality/internationalization/#add-text-domain-to-strings.
2. We suggested correcting potential syntax errors in the code, such as missing curly braces and ensuring the correct usage of single quotes in the text domain.
3. We recommended rescanning the theme or plugin for strings after making these corrections. For guidance on this process, visit https://wpml.org/documentation/getting-started-guide/string-translation/finding-strings-that-dont-appear-on-the-string-translation-page/#scan-the-theme-or-plugin.
4. Alternatively, if using another plugin to add code, the client might need to add the code directly to the theme's functions.php file or follow specific steps for that plugin as discussed in a related support ticket: https://wpml.org/forums/topic/code-snippet-text/.

If this solution does not apply to your case, or if it seems outdated, we 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. Should you need further assistance, please open a new support ticket 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.

Our next available supporter will start replying to tickets in about 7.93 hours from now. Thank you for your understanding.

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Mihai Apetrei 1 month, 2 weeks ago.

Assisted by: Mihai Apetrei.

Author Posts
September 28, 2024 at 6:33 am #16231603

bryantL-2

Background of the issue:
I implemented snippets and custom codes on my site hidden link, but I'm not able to translate the string in the snippets.

Symptoms:
Not able to translate the string in the snippets.

Questions:
How can I translate the string in custom code/snippets using WPML?

September 28, 2024 at 7:44 am #16231681

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+02:00)

Hi there.

Did you write the code with internationalization in mind?

You need to make sure that the echo contains the correct format.

Please take a look here:
https://developer.wordpress.org/themes/functionality/internationalization/#add-text-domain-to-strings

After that, rescan the theme or the plugin.

I hope that you will find this URL helpful 🙂

Please let us know how that goes.

Kind regards,
Mihai Apetrei

September 28, 2024 at 9:54 am #16231824

bryantL-2

Hi there, i'm using the text domain method in my snippet.

function display_membership_history($user_id) {
// Check if the user exists
$user = get_user_by('id', $user_id);
if (!$user) {
error_log('User not found for ID: ' . $user_id);
return __("User not found.", 'custom-membership-history');

text domain 'custom-membership-history', but i still can't view it in string translation.

September 28, 2024 at 12:32 pm #16232010

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+02:00)

Hi there.

At the moment:

1. There are two "}" missing at the end of this function. Maybe they exist but you did not pasted them here

2. Try to change this:

return __("User not found.", 'custom-membership-history');

to this:

return __('User not found.', 'custom-membership-history');

Then go and scan the theme or plugin:
https://wpml.org/documentation/getting-started-guide/string-translation/finding-strings-that-dont-appear-on-the-string-translation-page/#scan-the-theme-or-plugin

Please let me know how things go.

September 28, 2024 at 2:53 pm #16232217

bryantL-2

This is the snippets that i run in Code Snippet plugin. The guide not working for me as it only scan the string for the Code Snippet plugin.

September 29, 2024 at 7:23 pm #16233723

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+02:00)

Hi there.

I did not know that you are using another plugin where you add this code.

You can add this code straight to your theme's functions.php file or you will have to follow the steps explained by my colleagues here (in this existing ticket, the same thing happens - the code is added with the help of another plugin):
https://wpml.org/forums/topic/code-snippet-text/

I hope that you will find this information helpful.

September 30, 2024 at 5:31 pm #16237369

bryantL-2

Hi, the issue is resolved. I'm not using the suggested method. Instead, I use the Auto Registered Strings for Translations.

Thanks for the assistance.