mysociety / sobanukirwa-theme

The Alavateli theme for Sobanukirwa (Rwanda)
https://sobanukirwa.rw
MIT License
1 stars 3 forks source link

[ERROR] general#blog (ActionView::Template::Error) "comparison of String with 1 failed" #93

Closed garethrees closed 4 years ago

garethrees commented 4 years ago
An ActionView::Template::Error occurred in general#blog:

comparison of String with 1 failed
(eval):1:in `>'

-------------------------------
Request:
-------------------------------

* URL : https://sobanukirwa.rw/fr/blog
* HTTP Method: GET
* Parameters : {"controller"=>"general", "action"=>"blog", "locale"=>"fr"}
* Timestamp : 2020-09-25 17:40:35 +0200
* Rails root : /data/vhost/rwanda.alaveteli.org/alaveteli-2020-09-25T14-03-09

-------------------------------
Session:
-------------------------------

* session id: [FILTERED]
* data: {"session_id"=>"REDACTED", "locale"=>"fr"}

-------------------------------
Backtrace:
-------------------------------

(eval):1:in `>'
(eval):1:in `block (2 levels) in pluralisation_rule'
lib/i18n_fixes.rb:21:in `n_'
app/views/general/blog.html.erb:21:in `block in _app_views_general_blog_html_erb__3246849888494140887_70136296797820'
app/views/general/blog.html.erb:7:in `each'
app/views/general/blog.html.erb:7:in `_app_views_general_blog_html_erb__3246849888494140887_70136296797820'
app/controllers/application_controller.rb:118:in `record_memory'
lib/strip_empty_sessions.rb:15:in `call'
gbp commented 4 years ago

Doesn't effect other locales, can be reproduced with:

[1] pry(main)> AlaveteliLocalization.with_locale('rw') { FastGettext.n_("{{number_of_comments}} comment", "{{number_of_comments}} comments", "0").html_safe }
=> "{{number_of_comments}} comments"
[2] pry(main)> AlaveteliLocalization.with_locale('fr') { FastGettext.n_("{{number_of_comments}} comment", "{{number_of_comments}} comments", "0").html_safe }
ArgumentError: comparison of String with 1 failed
from (eval):1:in `>'
gbp commented 4 years ago

Full stack trace:

(eval):1:in `>'
(eval):1:in `block (2 levels) in pluralisation_rule'
fast_gettext (2.0.2) lib/fast_gettext/mo_file.rb:34:in `eval'
fast_gettext (2.0.2) lib/fast_gettext/mo_file.rb:34:in `block (2 levels) in pluralisation_rule'
fast_gettext (2.0.2) lib/fast_gettext/translation.rb:24:in `n_'
lib/i18n_fixes.rb:21:in `n_'
gbp commented 4 years ago

This doesn't seem to be related to translations done via Transifex as its erroring before the gettext interpolation.

garethrees commented 4 years ago

Guessing that we're getting string numbers rather than integers that we're using to compare against https://github.com/mysociety/alaveteli/blob/develop/app/views/general/blog.html.erb#L24 – probably just needs a #to_i.

gbp commented 4 years ago

Guessing that we're getting string numbers rather than integers that we're using to compare against https://github.com/mysociety/alaveteli/blob/develop/app/views/general/blog.html.erb#L24 – probably just needs a #to_i.

Yeah that'll do it. I have looked into why fr works differently to other locales and it seems its down to https://github.com/mysociety/sobanukirwa-theme/blob/master/locale-theme/fr/app.po#L22 where its doing n > 1 where as other locales have plural forms such as n != 1 which would return false when given a string.

garethrees commented 4 years ago

Ha! TIL

gbp commented 4 years ago

Reopening as this has not been deployed yet