Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
5282 Widoki

Hello,

I'm trying to send an email with a certain template which begin like this (I added the partner in the context to be able to access it in the template)

Hello ${ctx['partner'].title.name or ''} ${ctx['partner'].firstname or ''} ${ctx['partner'].lastname or ''},

and the language field is set up with 

${ctx['partner'].lang or ''}

My problem is that if the contact language is not in english, the email is correctly translated but the the title still appear in English. I checked and the translation is correctly set up for the title name. Is there a way to access the translation of the term through the template?

Awatar
Odrzuć
Najlepsza odpowiedź

It seems that you consruct 'ctx' under a user with different language rather than your partner language (e.g under the superuser).

Try something like:

ctx['partner'].with_context(lang=ctx['partner'].lang).title.name

By the way, why do you pass partner in context? Is there no way to retrieve it from a related object?


Awatar
Odrzuć
Autor Najlepsza odpowiedź

Thank you! This indeed solve the problem. Concerning the partner, the related object only contains a list of partners and I couldn't find a way to determine which one I was sending the mail to. The template and the code that send the email were written by someone else and I didn't want to change how it was called from fear of breaking something else.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
maj 24
4267
8
lis 20
33576
0
lis 20
2849
0
lut 19
3350
0
lut 18
4060