Internal Server Error caused by I18n::InvalidPluralizationData

AI-generated summary

A bug was reported where creating a post with more than two links triggers an Internal Server Error due to I18n::InvalidPluralizationData. The error occurs because the English locale file (server.en.yml) incorrectly includes a zero key, which violates official pluralization rules that only allow one and other keys. This issue was exacerbated by Transifex, which fails to detect pluralization keys if zero is present alongside one and other, leading to similar errors in other languages like Czech (server.cs.yml) that require few keys.

gerhard explained that the root cause is a mismatch between the English locale file and the Ruby I18n module’s special handling of the zero key. sam suggested a simple fix: splitting the translation into separate keys for no_links_allowed and too_many_links. gerhard agreed this is the easiest solution, noting there are about 20 keys affected. While jaromir asked for a quick patch, gerhard recommended manually adding the missing few keys or splitting the translations. Ultimately, gerhard submitted a Pull Request to address the issue: https://github.com/discourse/discourse/pull/3817.

When new user tries to create new post with more then 2 links then he receives “Internal server error”.

I found in /var/discourse/shared/standalone/log/rails/production.log the following:

Completed 500 Internal Server Error in 76ms (ActiveRecord: 12.5ms)
I18n::InvalidPluralizationData (translation data {:zero=>"Bohužel, návštěvníci nemohou vkládat odkazy do příspěvků.", :one=>"Bohužel, návštěvníci mohou do jednoho příspěvku vložit jen jeden odkaz.", :other=>"Bohužel, návštěvníci mohou do jednoho příspěvku vložit maximálně %{count} odkazů."} can not be used with :count => 2)
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/i18n-0.7.0/lib/i18n/backend/pluralization.rb:35:in `pluralize'

I have installed the latest version of discourse (latest-release +140, 1.4.0.beta12).

Jaro.

Translation error, as indicated in the error log message.

Well, actually it’s a problem in the English locale file that’s causing this.

server.en.yml contains the zero, one and other keys, but according to the official pluralization rules only one and other are allowed. It currently works for English (and all the other languages that use only one and other) because the Ruby I18n module has a special case for the zero key.

Unfortunately Transifex doesn’t handle the special case of zero, so it doesn’t detect any key as pluralized if there exists anything else than one and other in the English locale files.

That’s the reason why the server.cs.yml contains the zero, one and other keys instead of the required one, few and other.

There’s currently no easy way to fix this. I was planning on proposing a few solutions to this problem in the next few days.

3 Me gusta

Simplest fix is just splitting this translation, so zero has its own key

no_links_allowed
too_many_links

problem solved :slight_smile:

1 me gusta

Yes, splitting would be the easiest option. There are about 20 keys with this problem, so that shouldn’t be that much work.

1 me gusta

How can I patch our code to address this problem? I would put there something really simple ‘Too much links in your post. Try to remove few of them. Sorry.’.

You’d need to manually add the missing few keys in server.cs.yml:

Don’t forget to use the %{count} placeholder for those translations.


I’ll try to create a patch for this in the next few days unless someone else wants to do it? I’ve already implemented some tests to guard against the usage of the zero key in English locale files.

2 Me gusta

I submitted a PR:
https://github.com/discourse/discourse/pull/3817

2 Me gusta