New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
suggestion: template engine #311
Comments
could you give me an example? I use translations with post_office all the time and haven't had any problems with it, nor did I need to "hard-code" them in python files. |
Maybe I do not understand the documentation correctly but the following code would include the translation in the python code:
This would not be collected in the .po files for a translator and would force the translator to work on python files. The alternative that I provided renders a template that uses the conventional tags of {% load i18n %}. Hence, the strings will be collected by Django into the .po files for the translator. I guess it is a good alternative and it is no incompatible with the current solution. I see also that I am using the plugin in a different way. I do not want to set up manually the templates but ship them out-of-the-box. |
This is just an example. Normally you would do that in Django's admin backend, |
exactly that is my point. With the current system you will have to do this manually, but what if I need to deploy the app multiple times? For that use case, having a second option that can deliver translated templates with the base code would be a nice improvement. And it would be integrated in the translation workflow. |
Now I understand your use-case. What about doing it like: from django.conf import settings
from django.utils.translation import gettext_lazy
from post_office.models import EmailTemplate
template = EmailTemplate.objects.create(
name=_("hello"),
subject='Hello world!',
)
for language, _ in settings.LANGUAGES:
template.translated_templates.create(
language=language,
subject=gettext_lazy('Hello world!'),
body=gettext_lazy("""
Hello {{user.first_name}},
you have been selected for a free vacation to the Disney Land!
""") With |
Yes exactly that is the direction that I am suggesting.
This method could be integrated into the plugin as a class based template that takes either a string, as you suggested or a template file like in my first example. That would be a nice feature for the plugin. |
The correct place to add such fixtures is in the |
closing, since this issue seems to be solved. |
Hello,
I have a suggestion for the template handling. The problem with the current solution is that the translations are not very well integrated into the django translation system. The translations have to be "hard-coded" in python files and can not be easily sent to an external translator as they would expect .po files.
I propose here a solution which is fully integrated with the django translation system. Besides is it not incompatible with the current translation schema of post-office.
This also allows to ship templates out-of-the-box with Django applications and eliminates the need to set them up manually. They will be also automatically updated.
templates.py
The text was updated successfully, but these errors were encountered: