Rails 5: Can you pluralize two words in a string with two different counts?

Viewed 647

I'm building a view for a store that lists a summary of a product's reviews. I'm grouping the reviews by score, and I want a string at the top of each group of the form "10 reviews of 5 stars". I know that if I just wanted to pluralize "review", I could do this in en.rb:

en: {
  reviews_header: {
    one: "%{count} review",
    other: "%{count} reviews"
  }
}

Is there a format for the reviews_header hash that lets me specify counts for both "review" and "star" so they are both pluralized when necessary? In pseudo-code, I'm imagining something like:

en: {
    reviews_header: {
        counts: [ :review_count, :star_count ],
        review_count: {
            one: {
                star_count: {
                    one: "%{review_count} review with %{star_count} star",
                    other: "%{review_count} review with %{star_count} stars"
                }
            },
            other: {
                star_count: {
                    one: "%{review_count} reviews with %{star_count} star",
                    other: "%{review_count} reviews with %{star_count} stars"
                }
            }        
        }
    }
}

And I would get the string with t(:reviews_header, review_count: 10, star_count: 5).

What I'm doing for now is I changed the string to the form "10 5-star reviews", which gets around the problem of pluralizing "star", but that won't work in other languages.

1 Answers
Related