2

I have installed django countries today. It works pretty neat.

The documentation is unfortunately a bit thin, it says:

COUNTRIES A tuple of two part tuples, each consisting of a country code and the corresponding nicely titled (and translatable) country name.

Do I simply go down the usual path of django internationalization and it would automatically pick it up and allow me to define the countries in my PO file? Or is there any additional magic required?

The way I have implemented it is like this:

from django_countries.countries import COUNTRIES
from django_countries.fields import CountryField

country             = CountryField(_(u'Country'), choices=COUNTRIES,  blank=True)

COUNTRIES is coming directly from the extension, therefore I have no access to put _(u) around each country name. (from django.utils.translation import ugettext_lazy as _)

Houman
  • 64,245
  • 87
  • 278
  • 460

2 Answers2

10

For django-newbies like me: Adding 'django_countries' to INSTALLED_APPS in settings.py of your site will do the trick. So Aamir's answer is right - just check the section "How Django discovers translations" in documentation.

ecp
  • 2,199
  • 1
  • 12
  • 11
2

Just follow the django translation documentation and it will automatically add the ugettext_lazy marked strings into your .po file. And then provide message strings according to the language of your choice.

Aamir Rind
  • 38,793
  • 23
  • 126
  • 164
  • Thank Amir. You said `marked strings` are put into PO files. I am aware of that. But I can't mark the country strings directly as shown in the example. So how is the marking done in this case? This is the question :) – Houman Jan 09 '13 at 15:13
  • 1
    @Kave if browse the code of `django-countries` and go to `countries.py` you will notice that all countries names are marked strings already e.g. `('AF', _(u'Afghanistan')),` – Aamir Rind Jan 09 '13 at 15:16
  • @AamirAdnan - this is quite unfortunate if you have django_countries==1.0.5 (which I had), because it only translates the countries once, using system `dgettext`. I tried to hack around it, only to notice that the 1.5 version doesn't have this problem (it's using `ugettext_lazy`). This is a must, if you have a website with "live" language switching for users. – Tomasz Gandor Oct 15 '13 at 13:52