Hi there,

i have got a simple approach to make all django fields with a full
i18n support

the django.models.fields.Field class can be subclassed like this

from django.db import models
from django.utils.translation import get_language

class i18nField(models.Field):

    def __init__(self, i18n = False, *args, **kwargs)
        self.i18n = i18n
        models.Field.__init__(self, *args, **kwargs)

    def db_column_get(self):
        if not self.i18n:
            return self._db_column or self.name
        return "%s_%s" % (
            self._db_column or self.name,
            get_language().lower()
            )

    def db_column_set(self, value):
        self._db_column = value

    def _column_set(self, value):
        pass

    db_column = property(db_column_get, db_column_set)
    column = property(db_column_get, _column_set)

then you can declare all other subfields as usual

this work in that way: you need a separate db column for every
language installed.
a field called "name" needs to create ("name_%s" % code for code in
languages) columns

so the framework automatically select the right column in every query.

problems:
 - serializing objects, you need to serialize all all fields, not just
current language
 - many to many fields, to work they need to create an extra column in
every througth table, a column to store the language code.
 - during sync db you need to create a column for every language
installed

after two years on an i18n django site, i found this simple solution.
there are some small problems, that can be fixed if we put a i18n
option when you init a field, and solve some issue during syncdb
command and serialization of objects.

 for me is a very simple approch,
it automatically filter, sort and output the right queryset for your
language, and when you access a field you get the current language, it
works for every field, ForeignKeys too.

 and it works in admin (with no changes at all)

let me know what you think.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to