尝试翻译我的类的字段(Django)

2024-09-30 00:34:34 发布

您现在位置:Python中文网/ 问答频道 /正文

今天我在翻译我的培训项目,昨天我在读Django的书(Cap:国际化),我已经完成了完全翻译我的模板。现在我有一个新问题。我有一些动态内容,我想翻译,但我不知道如何继续除了添加ugettext的笔名:

from django.utils.translation import ugettext as _

在我的项目中,“产品”是我的动态内容,这是我的课程:

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文档、中间件等(基本配置),我只想将这些字段翻译成西班牙语

如果我疏忽了什么事,请提前道歉。任何贡献都是好的,谢谢你的评价


Tags: tonameselftrue内容modelsproductnull

热门问题