Skip to content

Fix #7388: use ungettext() for rating pluralization in star rating macros#12971

Merged
cdrini merged 3 commits into
internetarchive:masterfrom
Entropy-rgb:7388/fix/use_i18n_instead_of_manual
Jun 18, 2026
Merged

Fix #7388: use ungettext() for rating pluralization in star rating macros#12971
cdrini merged 3 commits into
internetarchive:masterfrom
Entropy-rgb:7388/fix/use_i18n_instead_of_manual

Conversation

@Entropy-rgb

@Entropy-rgb Entropy-rgb commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Replace manual singular/plural selection with ungettext('rating', 'ratings', ratings_count) in openlibrary/macros/StarRatingsByline.html and openlibrary/macros/StarRatingsComponent.html to support locale-aware plural forms.

Closes #7388

fix

Technical

Replaced manual singular/plural branching with ungettext() so that plural forms are handled correctly across all locales, not just English. The count is now embedded inside the ungettext string in StarRatingsComponent.html as required by the i18n guide. Removed unused ratings_label variable from StarRatingsByline.html.

Testing

  • A book with 1 rating displays "1 rating" (singular)
  • A book with multiple ratings displays "N ratings" (plural)
  • Checked trending.html — no rating pluralization logic present there, no changes needed

Screenshot

Stakeholders

@cdrini

@mekarpeles

Copy link
Copy Markdown
Member

Thank you @Entropy-rgb for this contribution — and welcome to Open Library! 🎉

🤖 Copilot has been assigned for an initial review.

@cdrini is assigned to this PR and currently has:

  • 5 open PR(s) of equal or higher priority to review first

Possible improvements for this PR

  • Testing section is empty — please add a brief note describing how you tested this change (e.g., confirming that a book page with 1 rating shows "1 rating" and multiple ratings show "N ratings" in the browser). A short description helps reviewers reproduce your verification steps. See Testing & Tools for guidance.
  • Pre-commit.ci auto-fix commit in history — there's a [pre-commit.ci] auto fixes commit on this branch. Consider squashing it into the main commit before merge (see the git cheatsheet).
PR triage checklist (maintainers / Richy)
  • PR description — not empty; explains what the change does and how to verify it
  • References an issue — PR body contains a #NNN reference
    • Linked issue is triaged — has a Priority: * label (not just Needs: Triage)
    • Linked issue is assigned — has at least one assignee
  • Commit history clean — no WIP/fixup/conflict noise; commit messages are meaningful
  • CI passing — no failing check-runs
  • Test cases present — if the change touches substantive logic, test coverage exists or is explained
  • Proof of testing — PR body includes a description of what was tested, a screenshot, or a video

Note

This comment was automatically generated by Richy, via PAM, Open Library's Project AI Manager, on behalf of @mekarpeles. Richy is designed to provide status visibility, perform basic project management functions and relevant codebase research, and provide actionable feedback so contributors aren't left waiting.

@mekarpeles mekarpeles added the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Jun 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates star rating macros to use locale-aware pluralization for the “rating/ratings” label by switching to ungettext(...), and refreshes the translation template accordingly.

Changes:

  • Replaced manual singular/plural branching with ungettext('rating', 'ratings', ratings_count) in star rating macros.
  • Updated messages.pot to represent “rating” as a pluralizable message (msgid/msgid_plural).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
openlibrary/macros/StarRatingsComponent.html Uses ungettext for the ratings label to support locale plural rules.
openlibrary/macros/StarRatingsByline.html Uses ungettext for the ratings label (but currently needs a None-safe count).
openlibrary/i18n/messages.pot Converts “rating/ratings” into a plural-form entry in the POT.

Comment thread openlibrary/macros/StarRatingsByline.html Outdated

@cdrini cdrini left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice great start @Entropy-rgb ! Two changes for you.

Also could you take a look at the issue in trending.html listed here? #7388 (comment) . Is this still an issue?

Comment thread openlibrary/macros/StarRatingsByline.html Outdated
Comment thread openlibrary/macros/StarRatingsComponent.html Outdated
@Entropy-rgb

Copy link
Copy Markdown
Contributor Author

Checked trending.html — it doesn't contain any rating pluralization logic, so no changes needed there.
Also rest I'll make the required changes in 2 minutes

@Entropy-rgb Entropy-rgb force-pushed the 7388/fix/use_i18n_instead_of_manual branch from 4bb8ac8 to 4cc8c26 Compare June 18, 2026 09:41
@github-actions github-actions Bot removed the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Jun 18, 2026
@Entropy-rgb Entropy-rgb requested a review from cdrini June 18, 2026 09:55
@github-actions github-actions Bot added the Needs: Response Issues which require feedback from lead label Jun 18, 2026

@cdrini cdrini left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! One small fix, and then will give this a test later today.

Comment thread openlibrary/macros/StarRatingsComponent.html Outdated
@cdrini cdrini force-pushed the 7388/fix/use_i18n_instead_of_manual branch 3 times, most recently from 2783c20 to d44adf1 Compare June 18, 2026 13:55

@cdrini cdrini left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a few more tweaks. Working great now!

Before:

image

After:

Image

Entropy-rgb and others added 3 commits June 18, 2026 16:01
… star rating macros

Replace manual singular/plural selection with `ungettext('rating', 'ratings', ratings_count)` in
`openlibrary/macros/StarRatingsByline.html` and `openlibrary/macros/StarRatingsComponent.html`
to support locale-aware plural forms.
…s and trending

- Add format_decimal() helper using babel for locale-aware decimal formatting
- Replace hardcoded "%.1f" and "{:,}".format() with format_decimal()/commify()
- Use ungettext() for plural-sensitive strings in trending.html

Co-Authored-By: Drini Cami <[email protected]>
@cdrini cdrini force-pushed the 7388/fix/use_i18n_instead_of_manual branch from d44adf1 to 84a59ab Compare June 18, 2026 14:01
@cdrini cdrini merged commit cc71ebd into internetarchive:master Jun 18, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Response Issues which require feedback from lead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plural form

4 participants