i18n strategy

1,718 views
Skip to first unread message

Brandon Taylor

unread,
Nov 6, 2008, 3:20:39 AM11/6/08
to Django users
Hi everyone,

I'm tasked with translating a mostly database-driven site into
Spanish. I'm familiar with how to use Django's internationalization on
static strings in templates, but not with text coming from a database,
so I'm looking for some best practices advice...

Should I:

1. Make a separate field for each translation and add a method in the
model to return the correct translation to use in templates?

2. Make a separate table for translations in general with a foreign
key to the original record and look up the translation that way?

Advice appreciated!
Brandon

Alex Koshelev

unread,
Nov 6, 2008, 3:25:46 AM11/6/08
to django...@googlegroups.com
The is an existing db internalization application - http://code.google.com/p/django-multilingual/. Try to look at it.

davidynamic

unread,
Nov 7, 2008, 1:08:40 PM11/7/08
to Django users
to quote the django internationizaton documentation...

"Using ugettext_lazy() and ungettext_lazy() to mark strings in models
and utility functions is a common operation. "

Getting data from your models requires you to place
django.utils.translation.ugettext_lazy() functions within the
arguments that you pass to the fields
that you create for your models.

you'll find your examples here.
http://docs.djangoproject.com/en/dev/topics/i18n/?from=olddocs#lazy-translation

Then you can use the same message (po) files you use when rendering
static strings in templates

Hope this helps

ilmarik

unread,
Nov 11, 2008, 7:02:10 AM11/11/08
to Django users
> Should I:
>
> 1. Make a separate field for each translation and add a method in the
> model to return the correct translation to use in templates?
>
> 2. Make a separate table for translations in general with a foreign
> key to the original record and look up the translation that way?

I think you should:

3. Save every item the same way as original(default language) with
information about i18n of its content.

for example:
for article, add one column to table, like 'i18n' or 'language'.
in my cms, every item can be langualized that way.

to receive correct items, I check what language is requested from URI
(domain.xx/en/articles/slug), store it by router, so whenever I need
main menu in another language, I simply gather rows with designated
lang. I may be used with complicated mechanisms too. easy, intuitive
and fast.

Reply all
Reply to author
Forward
0 new messages