法语翻译引发"ValueError('无效令牌,复数形式:%s'%value)" [英] French translation raises "ValueError('invalid token in plural form: %s' % value)"

查看:114
本文介绍了法语翻译引发"ValueError('无效令牌,复数形式:%s'%value)"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想处理法语版的网站.

I want to handle a french version of my website.

我将Django 2.2与i18n结合使用,并且已经在settings.py中设置了语言环境变量.

I use Django 2.2 with i18n and I already set locale variables in settings.py.

# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGES = (
    ('en', _('English')),
    ('fr', _('French')),
    ('it', _('Italian')),
    ('es', _('Spanish')),
)

LOCALE_PATHS = (
    os.path.join(BASE_DIR, 'locale'),
)

TIME_ZONE = 'Europe/Paris'

USE_I18N = True

USE_L10N = True

USE_TZ = True

当我使用./manage.py makemessages -l fr时,我正确地拥有django.po法语文件,但是在./manage.py compilemessages -l fr之后,服务器崩溃并出现以下错误(修剪过):

When I use ./manage.py makemessages -l fr, I correctly have a django.po french file but after ./manage.py compilemessages -l fr the server crashes with the following error (trimed) :

  File "/usr/lib/python3.7/gettext.py", line 93, in _tokenize
    raise ValueError('invalid token in plural form: %s' % value)
ValueError: invalid token in plural form: EXPRESSION

英语,意大利语和西班牙语的翻译效果很好

English, Italian and Spanish translations work well

嗯,问题已解决,但我不确定如何解决.我删除了venv,重新创建了它,然后法语翻译突然起作用了.从Django 2.2.1升级到2.2.2可能是导致此问题的原因.

EDIT : Well, the issue has been resolved, but I'm not really sure how. I deleted my venv, recreated it and french translation suddenly worked. Upgrading from Django 2.2.1 to 2.2.2 may be what caused the resolution.

推荐答案

对于其他遇到此错误的语言:

For other language facing this error:

有一行告诉Django评估此表达式,确定应使用哪种形式的单词,对于某些语言,该表达式未编写,例如波斯语.

There exists a line that tells Django evaluating this expression, decide which form of the word it should use, and for some languages, this expression is not written, e.g. Farsi.

对于这些语言,默认行会写在主.po文件中(而不是特定的行):

For these languages, a default line is written in your main .po file(not the specific ones):

"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

在这里EXPRESSION部分应更改为您的语言.

Here the EXPRESSION part should be changed to your language.

这里,您可以阅读EXPRESSION的确切格式,但如果您的语言只有单数和复数形式两种形式,则将行更改为:

HERE you can read the exact format of EXPRESSION, but for short if your language has just two forms for singular and plural form change the line to this:

"Plural-Forms: nplurals=2; plural=(n != 1);\n"

然后重新编译您的消息.

And recompile your messages.

这篇关于法语翻译引发"ValueError('无效令牌,复数形式:%s'%value)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆