| | 70 | |
|---|
| | 71 | One special case that isn't available in other gettext usages are lazily |
|---|
| | 72 | translated strings. This is needed for stuff that you set up in your django |
|---|
| | 73 | model files - those messages are stored internally and translated on access, but |
|---|
| | 74 | not translated on storage (as that would only take the default language into account). |
|---|
| | 75 | To translate a model helptext, do the following:: |
|---|
| | 76 | |
|---|
| | 77 | from django.utils.translation import gettext_lazy |
|---|
| | 78 | |
|---|
| | 79 | class Mything(meta.Model): |
|---|
| | 80 | |
|---|
| | 81 | name = meta.CharField('Name', help_text=gettext_lazy('This is the help text')) |
|---|
| | 82 | ... |
|---|
| | 83 | |
|---|
| | 84 | This way only a lazy reference is stored for the string, not the actual translation. |
|---|
| | 85 | The translation itself will be done when the string is used in a string context, like |
|---|
| | 86 | template rendering in the admin. |
|---|