Dear Veronica,
It’s finally working. Thanks to Google Language Translator and Ultimate Member, I have now a website that is multilingual – incl. multilingual emails. Rather simple and without the complexity of WPML. Love it! It’s really amazing how UM is built with many hooks and classes that are accessible for website creators so that UM can be tweaked and customized in many ways. Really amazing! I’m an even bigger fan of UM now ??
In case someone is looking for a similar solution, here’s how I did it:
1. When the user enters the webpage with registration or account form or when he changes the website language while being on the registration or account page, this JS snippet reads the current website language setting and stores it in a hidden UM field:
// Set user correspondence language from selected website language when entering the form
if ($($userCorrLang).val()=='') {
setTimeout(function() {$($userCorrLang).val(get_glt_language('en')).change()}, 500);
}
// GLT language change event to set user language in case user changes website language
$('.nturl').on('click', function() {
setTimeout(function() {$($userCorrLang).val(get_glt_language('en')).change()}, 500);
});
(get_glt_language(‘default lang’) is a custom function that reads the Google Language Translator cookie “googtrans” from the document cookie.)
2. My UM email templates are stored in the child theme in an admin and several language folders:
– Email templates for admin notifications: child-theme/ultimate-member/email/_admin
– Email templates for emails to users/members: child-theme/ultimate-member/email/<language> (a folder for each language, e.g. en)
3. Instruct UM to send emails from the above _admin and language folders, the language depending on the language setting in the recipient’s UM user data (the field that was filled in step 1), by using the UM’s um_email_template_path filter:
add_filter( 'um_email_template_path', 'my_email_template_path', 10, 3 );
function my_email_template_path( $located, $slug, $args ) {
$corr_lang = '';
if (UM()->config()->email_notifications[$slug]['recipient'] == 'admin') {
$corr_lang='_admin';
} else {
$corr_lang = um_user('user_corr_language');
if (!$corr_lang) {
$corr_lang='en';
}
}
$located = get_stylesheet_directory() . '/ultimate-member/email/' . $corr_lang . '/' . $slug . '.php';
return $located;
}
4. Instruct UM to use a subject in the appropriate language by using UM’s um_email_send_subject:
add_filter( 'um_email_send_subject', 'my_email_send_subject', 10, 2 );
function my_email_send_subject( $subject, $key ) {
$corr_lang = um_user('user_corr_language');
if (!$corr_lang || UM()->config()->email_notifications[$slug]['recipient'] == 'admin') {
return $subject;
}
switch ([$key, $corr_lang]) {
case ['checkmail_email', 'en']:
$subject = 'Your new {site_name} account: Please confirm email address'; break;
case ['checkmail_email', 'fr']:
...
// further cases for all user/member email types and languages
}
return $subject;
}
Thank you, Veronica. I really love the Ultimate Member plug-in, and I highly appreciate your great support!
Kind regards, Roger