0

I am using wp_mail() function to sending email. I have one static string "Hello Admin". My clients wants convert this string to language string. So it possible to convert static string to language string while sending email.

What I have done so far, please refer my below code.

$current_user = wp_get_current_user();
$admin_email = get_option('admin_email');
$subject = get_bloginfo('name').' - Publish Details';
$message  = _("Hello Admin,",'text-domain');
$message .= "$current_user->user_login has published details. Details are as following.\r\n";   

wp_mail($admin_email,$subject,$message,$headers)

Output:

John has published details. Details are as following.

I am not getting language string in email. Any help would be appreciate.

2

You have a typo in your code, the function is __() with two underscores. You will also need to configure the textdomain 'text-domain' and have a valid translation for the end users' browser settings for it to not default to english.

// use two underscores in the method
$message  = __("Hello Admin,",'text-domain');

// assuming this is a plugin and your language files are in a /languages subdirectory
function load_textdomain() {
    load_plugin_textdomain( 'text-domain', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
add_action( 'plugins_loaded', 'load_textdomain' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.