Hello! I don't know if there is already or someone has solved the problem, I have searched and found nothing by ninugn laho so I tried to make a hook with which to re-splice the date.
Actually I use the standard date in the DD/MM/YYYYYY commands, but at the end of the mails I had in the global template {$date} and I didn't realize that it arrived in English even though I have it in Spanish.
I made a small hook that could be adapted, for this I made a new varibale {$date_locale} that will be the output and the one that will remain in the template.
Then I read the client language that is given by default by the variables in the hook $vars['mergefields']]['client_language']
I tried Lang::trans but it didn't work so since we already get the client's language, I made an include to attach the client's language.
include ROOTDIR . "/lang/".$vars['mergefields']['client_language'].".php";
Now I read the date given by the varialbes and in this case I need "date" so I pass it to strtotime and then using arrays I replace it with $_LANG['dateTime'] and change the output format to my liking.
add_hook('EmailPreSend', 1, function($vars) {
$merge_fields = [];
if (!array_key_exists('date_locale', $vars['mergefields'])) {
include ROOTDIR . "/lang/".$vars['mergefields']['client_language'].".php";
$date = strtotime($vars['mergefields']['date']);
$NumberDay = date('j', $date);
$Day = date('l', $date);
$Month = date('F', $date);
$Year = date('Y', $date);
$Days_Translate = array(
$_LANG['dateTime']['monday'],
$_LANG['dateTime']['tuesday'],
$_LANG['dateTime']['wednesday'],
$_LANG['dateTime']['thursday'],
$_LANG['dateTime']['friday'],
$_LANG['dateTime']['saturday'],
$_LANG['dateTime']['sunday']
);
$Days_En = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
$NameDay = str_replace($Days_En, $Days_Translate, $Day);
$Month_Translate = array(
$_LANG['dateTime']['january'],
$_LANG['dateTime']['february'],
$_LANG['dateTime']['march'],
$_LANG['dateTime']['april'],
$_LANG['dateTime']['may'],
$_LANG['dateTime']['june'],
$_LANG['dateTime']['july'],
$_LANG['dateTime']['august'],
$_LANG['dateTime']['september'],
$_LANG['dateTime']['october'],
$_LANG['dateTime']['november'],
$_LANG['dateTime']['december']
);
$Months_EN = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$NameMonth = str_replace($Months_EN, $Month_Translate, $Month);
$merge_fields['date_locale'] = $NameDay.", ".$NumberDay." de ".$NameMonth." de ".$Year;
}
return $merge_fields;
});
As in my case I wanted the date when the mail was sent I used $vars['mergefields']['date'] but if you need another date you can use the ones allowed by the template for example from invoices: invoice_date_created and invoice_date_due etc.. and replace it with $vars['mergefields']['date'] ex : $vars['mergefields']]['invoice_date_created']
You can change the directory to include instead of the main language the one included in the overrides directory in case you want to make different settings or different texts and not lose it in the updates.
I hope it helps, I also have a hook to replace the image of 2co, Paypal and Stripe if you are interested.
Regards!