bensheldon / good_job

Multithreaded, Postgres-based, Active Job backend for Ruby on Rails.
https://goodjob-demo.herokuapp.com/
MIT License
2.69k stars 200 forks source link

Dashboard error when trying to display 0 running/queued/retried jobs due to missing 'zero' translation #990

Closed Roko131 closed 1 year ago

Roko131 commented 1 year ago

Hi, getting: translation data {:one=>"Apply to all 1 job.", :other=>"Apply to all %{count} jobs."} can not be used with :count => 0. key 'zero' is missing.

When clicking : for example clicking 0 queued jobs image

Because no zero value at apply to all (at any of the languages): https://github.com/bensheldon/good_job/blob/7971c8febdca9ee76555ec756e1257c34da4cd9a/config/locales/en.yml#L130-L134 So need to either add zero in all translations languages or adjust line 54 : t ".actions.apply_to_all", count: filter.filtered_count and somehow avoid count being zero

https://github.com/bensheldon/good_job/blob/7971c8febdca9ee76555ec756e1257c34da4cd9a/app/views/good_job/jobs/_table.erb#L48-L57

bensheldon commented 1 year ago

Thanks for opening this issue! I'll add a zero onto those keys.

bensheldon commented 1 year ago

hmmm, I'm having trouble reproducing this. Those helpers don't require a zero for me, so I'm a little confused about why your setup would 🤔

Screenshot 2023-06-28 at 7 19 57 AM
bensheldon commented 1 year ago

Doing a little research, it seems like the i18n gem asserts pluralize "...will pick the :zero subkey in the special case where count is equal to 0 and there is a :zero subkey present."

https://github.com/ruby-i18n/i18n/blob/7cf09474b77fd41e65d979134b0525f67cf371b0/lib/i18n/backend/base.rb#L168-L170

Which matches up with the code:

https://github.com/ruby-i18n/i18n/blob/7cf09474b77fd41e65d979134b0525f67cf371b0/lib/i18n/backend/pluralization.rb#L48

😕 So I'm not sure why your application is specifically expecting a zero key. Are there other I18n-related gems that you're using or something that has been patched into your application?

Edit: this also matches up with the Rails translation docs too: https://guides.rubyonrails.org/i18n.html#pluralization

The translation denoted as :one is regarded as singular, and the :other is used as plural. If the count is zero, and a :zero entry is present, then it will be used instead of :other.

Roko131 commented 1 year ago

You are correct, it is specifically related to my application configuration- my bad.

This is the culprit: config/locales/plurals.rb:

{:en =>
  { :i18n =>
    { :plural =>
      { :keys => [:zero, :one, :other],
        :rule => lambda { |n|
          if n == 1
            :one
          elsif n == 0
            :zero
          else
            :other
          end
        }
      }
    }
  }
}