Internationalization of models in Django applications

前端 未结 3 632
轻奢々
轻奢々 2021-01-20 11:32

My application will be available in two languages: english and german. The application will have a couple of XType objects with a description field. How can I translate the

相关标签:
3条回答
  • 2021-01-20 11:41

    Check one of those add-ons: http://www.google.pl/search?sourceid=chrome&ie=UTF-8&q=django+model+translation for a flexible solution

    0 讨论(0)
  • 2021-01-20 11:48

    Django does not provide direct support of model field translations.

    You have to find a way to deal with it either within Django or via plugable applications (like posted already django-easymode or check http://blog.muhuk.com/2010/01/06/dynamic-translation-apps-for-django.html).

    If you want to deal within your app with it you might want to try something like saving one instance per language and then filter accordingly when retrieving data:

    class XType(models.Model):
        language = models.CharField(max_length=5)
        description = models.CharField(max_length=50) 
    

    Depends of course a lot on your project needs.

    0 讨论(0)
  • 2021-01-20 11:53

    django-easymode includes the @i18n decorator, which may solve your case:

    At times it becomes a requirement to translate models. Django supports internationalization of static text in templates and code by means of gettext. For translation of models - dynamic data - easymode offers simple decorators to enable internationalized model fields and localized admin classes.

    0 讨论(0)
提交回复
热议问题