[英]Django parler: error when same translation for different languages
EDIT : my bad, i had:编辑:我的错,我有:
translations = TranslatedFields(
title=models.CharField(_('Title'), unique=False, max_length=40, null=False, blank=False)
)
I had unique=True
, that was the reason, so now the question is how do I require unique title for each language (for example, so there is only one 'Sport' for english language but not in general including all the translations), can I add constraint directly in models.py
?我有
unique=True
,这就是原因,所以现在的问题是我如何要求每种语言的唯一标题(例如,英语只有一个“运动”,但通常不包括所有翻译),我可以直接在models.py
中添加约束吗?
--------------------------------------------------- ---------------------------------------------- -
I've just added django-parlel to my project and I'm wondering is it my bad or it's really impossible to have same translation more then once .我刚刚将django-parlel添加到我的项目中,我想知道这是我的错还是真的不可能多次进行相同的翻译。
Case I'm trying to add translation for Polish language for word "Sport", in polish it would be "Sport", just same as in English (which I have by default in app).案例我正在尝试为单词“Sport”添加波兰语翻译,在波兰语中它将是“Sport”,就像英语一样(我在应用程序中默认使用)。 When trying to add this getting error both when adding from admin panel and when loading fixture .
在从管理面板添加和加载fixture时尝试添加此获取错误。 I know that i might leave it blank and it won't really be that bad however I need to have translation for each single word.
我知道我可能会将它留空并且它不会真的那么糟糕但是我需要为每个单词进行翻译。 I'm assuming there is a constraint in parlel
我假设并行有一个约束
Polish:
Please correct the error below.
Interests Group Translation with this Title already exists.
Interests Group Translation with this Title already exists.
Title: [Sport]
django-parlel settings: django-并行设置:
PARLER_LANGUAGES = {
None: (
{'code': 'en',}, # English
{'code': 'pl',}, # Polish
{'code': 'uk',}, # Ukrainian
),
'default': {
'fallbacks': ['en'],
'hide_untranslated': False,
}
}
Model: Model:
class InterestsGroup(TranslatableModel):
'''
Group for storing similar interests (that are related to same topic)
'''
translations = TranslatedFields(
title=models.CharField(_('Title'), unique=True, max_length=40, null=False, blank=False)
)
class Meta:
verbose_name = _('Interests Group')
verbose_name_plural = _('Interests Groups')
ordering = ['id']
Adding this solved my problem:添加这个解决了我的问题:
translations = TranslatedFields(
title=models.CharField(_('Title'), unique=False, max_length=40, null=False, blank=False),
meta={'unique_together': [('language_code', 'title')]} # unique title for each single language/translation
)
I would use this modeltranslation package我会用这个模型翻译 package
I also used django-parler and I think it's better to use modeltranslation instead of django-parler.我还使用了 django-parler,我认为使用 modeltranslation 而不是 django-parler 更好。 There will not be a problem about writing same text in different languages and it is also have tabbed view like django-parler
用不同的语言编写相同的文本不会有问题,它也有像 django-parler 这样的选项卡视图
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.