diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index c546462f144..f15202c3861 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1038,7 +1038,7 @@ class FormMail extends Form $defaultlines = $arraydefaultmessage->content_lines; if (isset($defaultlines)) { foreach ($this->substit_lines as $lineid => $substit_line) { - $lines .= make_substitutions($defaultlines, $substit_line)."\n"; + $lines .= make_substitutions($defaultlines, $substit_line, $outputlangs)."\n"; } } $this->substit['__LINES__'] = $lines; @@ -1083,7 +1083,10 @@ class FormMail extends Form if (GETPOSTISSET("message") && !GETPOST('modelselected')) { $defaultmessage = GETPOST("message", "restricthtml"); } else { - $defaultmessage = make_substitutions($defaultmessage, $this->substit); + // Pass $outputlangs so __(TranslationKey)__ in the template body is resolved + // in the language of the selected email template, not the operator's language + // (see issue #34540). + $defaultmessage = make_substitutions($defaultmessage, $this->substit, $outputlangs); // Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty) $defaultmessage = preg_replace("/^(
)+/", "", $defaultmessage); $defaultmessage = preg_replace("/^\n+/", "", $defaultmessage); @@ -1460,7 +1463,7 @@ class FormMail extends Form */ public function getHtmlForTopic($arraydefaultmessage, $helpforsubstitution) { - global $langs, $form; + global $conf, $langs, $form; $defaulttopic = GETPOST('subject', 'restricthtml'); @@ -1472,7 +1475,17 @@ class FormMail extends Form } } - $defaulttopic = make_substitutions($defaulttopic, $this->substit); + // Resolve __(TranslationKey)__ in the language of the selected template + // (see issue #34540). Falls back to the caller's language when the template + // has no explicit language pinned. + $outputlangs = $langs; + if (is_object($arraydefaultmessage) && !empty($arraydefaultmessage->lang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($arraydefaultmessage->lang); + $outputlangs->load('other'); + } + + $defaulttopic = make_substitutions($defaulttopic, $this->substit, $outputlangs); $out = ''; $out .= '';