Tutorial by Examples

Setting up settings.py from django.utils.translation import ugettext_lazy as _ USE_I18N = True # Enable Internationalization LANGUAGE_CODE = 'en' # Language in which original texts are written LANGUAGES = [ # Available languages ('en', _("English")), ('de', _("Germ...
When using non-lazy translation, strings are translated immediately. >>> from django.utils.translation import activate, ugettext as _ >>> month = _("June") >>> month 'June' >>> activate('fr') >>> _("June") 'juin' >>> a...
To enable translation in templates you must load the i18n library. {% load i18n %} Basic translation is made with the trans template tag. {% trans "Some translatable text" %} {# equivalent to python `ugettext("Some translatable text")` #} The trans template tag supports ...
To translate strings, you will have to create translation files. To do so, django ships with the management command makemessages. $ django-admin makemessages -l fr processing locale fr The above command will discover all strings marked as translatable within your installed apps and create one l...
(u)gettext_noop allows you to mark a string as translatable without actually translating it. A typical use case is when you want to log a message for developers (in English) but also want to display it to the client (in the requested language). You can pass a variable to gettext, but its content wo...
fuzzy translations Sometimes makemessages may think that the string it found for translation is somewhat similar to already existing translation. It will when mark it in the .po file with a special fuzzy comment like this: #: templates/randa/map.html:91 #, fuzzy msgid "Country" msgstr...

Page 1 of 1