Yogi Yogi - 3 months ago 23
Python Question

What is the use of gettext when django explicitly translates from .po and .mo files?

While I study Internationalisation and Localisation in Django, I am told to install gettext application in my windows. But I can see that the translation is done by the django with the translation strings that we type in .po files.

So I can visualise the process that when user selects a particular language, django pulls their language particular strings from .po files in which WE translated the default language.

I cannot understand where gettext is used in this process ? in the beginning I thought gettext is used to translate by itself, but it does not.


As you can see from the main point of entry in the django translation source

Django internally uses gettext to do the translations

trans_real imports gettext here here

Assuming you have the correct settings applied.

Why does django use gettext rather than make its own translation code? For the same reason, people choose to use existing libraries than write their own (maintenance, testing, etc) as well as the fact that its been around for over 20 years which means anyone coming from an existing project, would have an easier time of integrating it into django.