Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The best/recommended way to translate Django database values

I'm trying to figure out the best way to translate actual database values (textual strings, not date formats or anything complicated) when internationalizing my Django application. The most logical ways I could come up with were to either:

  • hold a database column for every language (e.g. description_en, description_de, description_fr, ...) or
  • have a different database for every language (e.g. schema_en, schema_fr, schema_de, ...).

Are these the best options, or is there something else I'm missing? Thanks.

like image 649
sa125 Avatar asked Jan 07 '10 09:01

sa125


People also ask

What is lazy text in Django?

Use the lazy versions of translation functions in django. utils. translation (easily recognizable by the lazy suffix in their names) to translate strings lazily – when the value is accessed rather than when they're called. These functions store a lazy reference to the string – not the actual translation.

What is internationalization in Django?

The goal of internationalization and localization is to allow a single web application to offer its content in languages and formats tailored to the audience. Django has full support for translation of text, formatting of dates, times and numbers, and time zones.

Which support Django to use multilingual websites through its built in internationalization system to develop the websites which would support multiple languages?

Multilingual Support − Django supports multilingual websites through its built-in internationalization system. So you can develop your website, which would support multiple languages. Framework Support − Django has built-in support for Ajax, RSS, Caching and various other frameworks.


2 Answers

I was reading up on my django extensions, and found the django-modeltranslation plugin. It seems to do exactly what you want it to do.

like image 64
extraneon Avatar answered Sep 22 '22 02:09

extraneon


I also found this small project which purpose is to synchronize localized strings into standard message files for fields of registered models.

Example:

import vinaigrette vinaigrette.register(YourModel, ['name', 'description']) 

The standard command

$ manage.py makemessages 

Would maintain messages for each distinct values found in registered fields.

I have not had the occasion to try it yet.
But this seems for me to be the simplest way to translate data from db.

like image 45
Pierre de LESPINAY Avatar answered Sep 23 '22 02:09

Pierre de LESPINAY