I want to use a string which is not in use yet. so there is no any {% trans 'word_I_want_to_use' %}
in template nor in views/models yet.
can I just create it like this in views.py?
from django.utils.translation import ugettext as _
_("word_I_want_to_use")
and makemessages
and compilemessages
.
and later on, I will put the {% trans 'word_I_want_to_use' %}
in template.
will this work?
Yes. That will work. You can also use lazy translation , so that you have no performance impact for the unused translation:
from django.utils.translation import ugettext_lazy as _
_("word_I_want_to_use")
Alternatively, you can use ugettext_noop
for only translating but never directly using the string. This depends on you plans and use case.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.