doniyor
doniyor

Reputation: 37846

django - i18n - create translation but use it later?

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?

Upvotes: 0

Views: 74

Answers (1)

Boldewyn
Boldewyn

Reputation: 82724

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.

Upvotes: 3

Related Questions