IMHO, that is very definitely the wrong way to do i18n! I say this from
a position of authority, as I have had to maintain systems like this in
the past, and it is just Plain Wrong :)
i18n is a very tricky topic, fortunately very smart people have spent a
long long time to come up with the best solution - gettext. It is
builtin to python, and is well supported by django. Read more about it
here:
http://docs.djangoproject.com/en/dev/topics/i18n/#topics-i18n
Your scenario is slightly more complicated than the examples shown
there, but the principle is the same. Instead of having separate fields
for each language translation, your field holds the key phrase which is
then used to lookup the correct translation in a gettext catalog.
Your change to your model would look like this:
class Country(models.Model):
description = models.CharField(...)
def __unicode__(self):
return ugettext_lazy(self.description)
I'm afraid this isn't a magic bullet though, for two reasons:
1) Your main aim seems to be to allow natural language ordering? I'm not
entirely sure how one could achieve that, as the ordering is done as
part of the DB query, which would not have access to the gettext catalog
- any ideas anyone?
2) As you add more instances of your model, you would need to be able to
add the translation of the description to the gettext catalog. This
might be fine in this specific case (how many countries will be
dynamically added later?), but wouldn't be for something slightly more
dynamic, like tag names. Again, any ideas anyone?
i18n, l10n and collation are pet peeves of mine, I am still yet to find
excellent solutions to all of these problems :)
Cheers
Tom
I have worked on making django-countries working with 1.1:
http://github.com/kaikuehne/django-countries/tree/master
There's also a branch which uses django-multilingual which I created
but not published. If you'd need that, I could polish it and put in on
github too.
On Wed, May 20, 2009 at 1:16 PM, Wouter van der Graaf <wou...@dynora.nl> wrote:
> If your app changes the default ordering of the country list to the
> language in request.LANGUAGE_CODE (the user specified language) then
> that's a good option for me.
It uses django-multilingual which itself uses the default language set
by django:
http://docs.djangoproject.com/en/dev/topics/i18n/#id2