尝试翻译我的 类 字段(Django 国际化上限)

Trying to translate fields of my classes (Django internationalization Cap)

今天我正在翻译我的培训项目,昨天我正在阅读 The Django book (Cap: Internationalization),我已经完全翻译了我的模板。现在我有一个新问题。我有一些想要翻译的动态内容,但是 除了添加 ugettext 的笔名之外,我不知道如何进行:

from django.utils.translation import ugettext as _

在我的项目中 "Products" 是我的动态内容,这是我的 class:

class Product(TimeStampModel):

    name = models.CharField(max_length=200, unique=True)
    slug = models.SlugField(editable=False)
    # Product Images
    pimage0 = models.ImageField(upload_to = 'prodimg')
    pimage1 = models.ImageField(upload_to = 'prodimg')
    pimage2 = models.ImageField(upload_to = 'prodimg')
    pimage3 = models.ImageField(upload_to = 'prodimg')
    # END Product Images
    size = models.CharField(max_length=50)
    content = models.TextField()
    content1 = models.TextField(blank=True, null=True)
    content2 = models.TextField(blank=True, null=True)
    # Product Stats
    tolerance = models.CharField(max_length=3)
    efficiency = models.CharField(max_length=3)
    performance = models.CharField(max_length=3)
    lowrad = models.CharField(max_length=3)
    # END Product Stats
    # Other Features
    protection = models.TextField(null=True)
    protection1 = models.TextField(blank=True, null=True)
    environments = models.TextField()
    environments1 = models.TextField(blank=True, null=True)
    # END Other Features
    # Key Features
    kfeature0 = models.ImageField(upload_to = 'kfeats')
    kfeature1 = models.ImageField(upload_to = 'kfeats')
    # END Key Features
    category = models.ForeignKey(Category)

    def save(self, *args, **kwargs):
        if not self.id:
            self.slug = slugify(self.name)
        super(Product, self).save(*args, **kwargs)

    def __str__(self):
        return self.name

为了在模板上呈现它,我使用了这个视图:

class SingleProView(DetailView):

    template_name = 'products/single_product.html'
    model = Product

我想将这些字段翻译成西班牙语:

内容、内容 1、内容 2、保护、保护 1、环境、环境 1

我应该修改 models.py 还是 views.py?

目前我的翻译仅限于模板,因此您可以自由假设我已经完成相应的 locale 目录配置,.po .mo 文档,中间件等(基本配置),我只想将这些字段翻译成西班牙语。

如有遗漏请提前致歉。欢迎投稿,感谢评价!

开箱即用的 Django 不支持模型翻译。

这些包实现了该功能: