0

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.

Yogi
  • 1,561
  • 5
  • 26
  • 45
  • 1
    Django uses `gettext` to do the translations – Sayse Oct 27 '16 at 08:47
  • to display the translated content in the .po files which are hard typed by us? If so, why do we need gettext? it can just be done by django to pull the translated content from .po files to the user. – Yogi Oct 27 '16 at 08:50
  • 1
    `gettext` is the thing that interprets `.po` and `.mo` files, they aren't django files – Sayse Oct 27 '16 at 08:52
  • 1
    now i understand, thanks :P – Yogi Oct 27 '16 at 08:58
  • 1
    No worries, I also noticed you said you manually hard type the po files... you may want to check out [poedit](https://poedit.net/) – Sayse Oct 27 '16 at 08:59

1 Answers1

1

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.

Sayse
  • 42,633
  • 14
  • 77
  • 146
  • Okay, if I am understood correct, gettext is used to read the .po files and compile them to .mo files. Now, the compiled .mo files are used by django to provide the translation. – Yogi Oct 27 '16 at 09:24
  • 1
    @Yogi - Not quite.... `gettext` is still the thingthat reads the mo files, but then django uses that to construct catalogs of locales using its [translation class](https://github.com/django/django/blob/master/django/utils/translation/trans_real.py#L95)... or at least this is my understanding – Sayse Oct 27 '16 at 09:27
  • 1
    awesome.. I can see that now. thanks again. Hard for a mechanical engineer. – Yogi Oct 27 '16 at 09:40
  • @Yogi - No worries, its best just to keep thinking of it as "string" goes in, "chaîne" comes out – Sayse Oct 27 '16 at 09:41