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?
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
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.
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.
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.