Skip Navigation

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 3.47 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 9:00 – 13:00 9:00 – 13:00 -
- 15:00 – 19:00 15:00 – 19:00 15:00 – 19:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Europe/Bucharest (GMT+03:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by bryantL-2 10 hours, 39 minutes 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+03: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+03: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.