问题
I want to run an article site on several languages, I already translated translation strings, so my templates are ready. I only have a questions how to store articles in many languages? Should I create a database for each translation or it works in different way?
If I have for example this basic model:
class Article(models.Model):
models.TextField()
And want to store data in many languages, how do I do it? How to organize redirects between one article on different languages
回答1:
One simple approach to this problem is to add a "language" field in each model which identifies the language used for each record. This seems to be the approach used by django-pluggable-model-i18n.
Another approach is to use Python metaclasses to identify fields for translation, as used by django-translate and django-transmeta.
There are several other projects but many of them seem abandoned or lower quality. Django-transmeta always seemed the most interesting to me.
Edit: muhuk just wrote an excellent article today reviewing different translation projects: http://www.muhuk.com/2010/01/dynamic-translation-apps-for-django/
回答2:
There is also: django-multilingual
回答3:
Take a look at how folks at django-cms solved this problem- you can also get your hands dirty and extract the portions of code that are responsible for nice multilingual urls (e.g. url http://site.com/en-us/some_view/ routes correctly to some_view/ and sets request.LANGUAGE_CODE to en-us).
来源:https://stackoverflow.com/questions/1984327/django-running-site-on-many-languages