views:

1973

answers:

8

Hey, i am currently working on a django app for my studies, and came to the point of l18n. Localizing the site itself was very easy, but now i have to allow users, to translate the dynamic content of the application. Users can save "products" in the database and give them names and descriptions, but since the whole site should be localized, i must provide a way of translating theses names and descriptions to the users.

Is there a natural way in django to do this? Or do i have to realize it as part of the application (by representing the translations in the datamodel)

Thanks, Janosch

A: 

It depends on who will provide the translations. If you want to provide a web interface to translation, then you need to develop that yourself, and also represent the translations in the database.

If the same translators who translated the site will also translate the data, you can provide them with the same model that they use for the site (presumably gettext), and you can then also use gettext for this content.

Martin v. Löwis
+1  A: 

"i must provide a way of translating theses names and descriptions to the users."

"Is there a natural way in django to do this?"

Are you asking if Django can translate from language to language? Are you asking about something like http://translate.google.com/ ?

I don't think Django can translate user input into another language.

If you are going to do the translation for your users, this must be part of your data model.

Django's i18n filter allows you to have a table of translation strings. The documentation says this.

  1. Embed translation strings in your Python code and templates.
  2. Get translations for those strings, in whichever languages you want to support. This is something you do manually, by hiring translators or knowing a lot of languages yourself.
  3. Activate the locale middleware in your Django settings.
S.Lott
+4  A: 

I would suggest checking out django-multilingual. It is a third party app that lets you define translation fields on your models.

Of course, you still have to type in the actual translations, but they are stored transparently in the database (as opposed to in static PO files), which is what I believe you are asking about.

Prairiedogg
+4  A: 

There are two projects of note for translatable content in Django: http://code.google.com/p/django-multilingual/ http://code.google.com/p/transdb/

Alex Gaynor
+5  A: 

I use django-multilingual for localize content and django-localeurl for choosing language based on url (for example mypage/en/).

You can see how multilingua and localeurl work on JewishKrakow.net page.

Marcin Mierzejewski
A: 

Also looking for content localization plugin, or how to write it. Can add to the list django-i18n-model

A: 

I think you should operate in two steps:

  1. Get translations
  2. Show translated strings

For the first step, you should tell Django that the user-inserted strings are to be translated. I think there is no native way to do so. Maybe you can extract the strings from your db putting them in locale-specific files, run 'makemessages' on them, obtaint django.po files and translate.

Second, use ugettext to show those strings on your web application.

Hope this can help the ones with your same problem.

Don
A: 

Or try this:

http://packages.python.org/django-easymode/i18n/index.html

It stays very close to how you would normally do a django model, you just add 1 decorator above your model. It has admin support for the translated fields, including inlines and generic inlines. Almost anything you can do with regular models and admin classes you can do with the internationalized versions.

specialunderwear