How to fix "plural forms expression could be dangerous"

556 views
Skip to first unread message

Martin Brochhaus

unread,
May 18, 2017, 6:58:58 AM5/18/17
to Django users
Hi everyone,

in my project, I am generating my .po files like this:

python manage.py makemessages --ignore=node_modules/* --ignore=*migrations/* --ignore=*tests/* --ignore=__init__.py --ignore=submodules/* --ignore=fabfile* -l zh_CN

Usually this results in the following line being added to my `django.po` file:

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

When this line is in the file and when I switch the language to Chinese, I will get this error:

ValueError at /zh-cn/
plural forms expression could be dangerous

When I delete that line and run `./manage.py compilemessages`, everything seems to work fine, but this is obviously can't be a good solution and would mess up my deployment workflow quite a bit.

So my question is: Why does this line pop up in my .po file? What if I change that expression to something valid, would it be overwritten with that same faulty expression again when I run makemessages? What would a correct expression look like for Chinese?

Best regards,
Martin

Tom Evans

unread,
May 18, 2017, 7:22:04 AM5/18/17
to django...@googlegroups.com
You need to change INTEGER and EXPRESSION for the correct values. I
believe for zh you want "nplurals=1; plural=0;"

Cheers

Tom
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5db9fbc1-9f59-4947-a214-0af82c8c4458%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Martin Brochhaus

unread,
May 21, 2017, 10:33:16 PM5/21/17
to Django users
Thanks for the reply, Tom.

Inserting those values does indeed make the error go away, but I am still left with the issue that on each deployment, when I run `./manage.py makemessages`, it overwrites that line with the faulty one and my site is left in a broken state.

Anyone knows how to prevent this line from being overwritten all the time?
Reply all
Reply to author
Forward
0 new messages