Skip to content

Recieved notification from a project with the wrong language #612

@davidbeig

Description

@davidbeig

When receiving a notification sent from a project the template content of the email is not in my communication preferred language.

static public function createFromTemplate(
string $to,
string $to_name,
string $template,
array $vars =[],
string $lang = null
): Mail
{
$mail = new static();
$mail->to = $to;
$mail->toName = $to_name;
$mail->html = true;
if($to == 'any') $mail->massive = true;
// Obtenemos la plantilla para asunto y contenido
if(empty($lang)) $mail->lang = Lang::current();
$tpl = Template::get($template, $lang);
// Sustituimos los datos
$mail->subject = $tpl->title;
$mail->template = $tpl->id;
$text = $tpl->text;
$mail->content = $text;
// En el contenido:
if($vars) {
$mail->content = str_replace(array_keys($vars), array_values($vars), $mail->content);
$mail->subject = str_replace(array_keys($vars), array_values($vars), $mail->subject);
}
$mail->lang = $lang;
return $mail;
}

As we can see in the code it takes the template using the $lang of the user doing the action, not the user receiving it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions