My Django app uses some strings that are already translated in Django. In custom templates for password reset process I'd like to use some of the original texts, like this one prompting user to log in after completing the reset process.
Custom template contains <p>{% trans "Your password has been set. You may go ahead and log in now." %}</p>
taken directly from the original form file.
After running django-admin makemessages
my .po file contains this:
#: core/templates/auth/password-reset-complete.html:10
msgid "Your password has been set. You may go ahead and log in now."
msgstr ""
Translation is working, rendered page already contains the correct translated string. Is it possible to ommit this empty translation from .po file automatically? Simply removing it will only work until I run makemessages
again. It's already been translated, to duplicate it in my .po file seems unnecessary.
These hooks are called translation strings. They tell Django: “This text should be translated into the end user’s language, if a translation for this text is available in that language.” It’s your responsibility to mark translatable strings; the system can only translate strings it knows about.
The Django translation mechanisms can be used to translate arbitrary texts to any language that is supported by Django (as long as an appropriate translation catalog exists, of course).
If you do not supply a user, the command will attempt to change the password whose username matches the current user. Specifies the database to query for the user. Defaults to default. This command is only available if Django’s authentication system ( django.contrib.auth) is installed. Creates a superuser account (a user who has all permissions).
When comes to using multiple languages in one single site, Django is very handy. You can use .po file to do your translation for you. Process is very simple: First create .po file. To make .po file I would suggest to use poedit or Rosetta. Here is another option that is using django’s very own Localisation.
You can try putting your string into a variable before giving it to trans
, so that makemessages
doesn't notice it. Something like
{% with mystr="Your password has been set. You may go ahead and log in now." %}
{% trans mystr %}
{% endwith %}
Alternatively, you could create your own custom template tag that simply calls gettext
(from django.utils.translation
) on its argument, and use that instead of trans
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With