Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Roko131 opened this issue Jun 28, 2023 · 4 comments
Labels
bug Something isn't working localization Updating localization strings

Comments

@Roko131
Copy link

Roko131 commented Jun 28, 2023

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):

table:
actions:
apply_to_all:
one: Apply to all 1 job.
other: Apply to all %{count} jobs.

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

<label role="row" class="list-group-item list-group-item-warning list-group-item-action py-3 d-none" data-checkbox-toggle-show="job_ids">
<div class="row">
<div class="col-auto">
<%= check_box_tag "all_job_ids", 1, false, disabled: true, data: { "checkbox-toggle-show": "job_ids"} %>
</div>
<div class="col-auto">
<%=t ".actions.apply_to_all", count: filter.filtered_count %>
</div>
</div>
</label>

@bensheldon
Copy link
Owner

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

@bensheldon bensheldon added bug Something isn't working localization Updating localization strings labels Jun 28, 2023
@bensheldon
Copy link
Owner

bensheldon commented Jun 28, 2023

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
Copy link
Owner

bensheldon commented Jun 28, 2023

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
Copy link
Author

Roko131 commented Jun 28, 2023

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
        }
      }
    }
  }
}

@Roko131 Roko131 closed this as completed Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working localization Updating localization strings
Projects
Development

No branches or pull requests

2 participants