Skip to content

Keep uncountable words as they are in plural and singular - #639

Open
zsnakeee wants to merge 3 commits into
laravel:0.xfrom
zsnakeee:uncountable-words
Open

zsnakeee wants to merge 3 commits into
laravel:0.xfrom
zsnakeee:uncountable-words

Conversation

@zsnakeee

@zsnakeee zsnakeee commented Dec 3, 2026 •

Copy link
Copy Markdown

plural and singular hand every word to the pluralizer crate, which inflects many words that Laravel leaves alone:

"money".plural()       // before: "monies",        after: "money"
"feedback".plural()    // before: "feedbacks",     after: "feedback"
"furniture".plural()   // before: "furnitures",    after: "furniture"
"related".plural()     // before: "relateds",      after: "related"
"species".singular()   // before: "specie",        after: "species"
"data".singular()      // before: "datum",         after: "data"
"trousers".singular()  // before: "trouser",       after: "trousers"

The doc comment on plural already says uncountable words stay as they are. The wrong forms also reach constrained(), so foreign_id("feedback_id").constrained() references a feedbacks table, while Laravel PHP's references feedback.

Laravel PHP's Pluralizer keeps recommended and related as they are and leaves the rest to Doctrine's English inflector (Rules/English/Uninflected.php). inflect now checks the last word, ignoring case, against the same lists before it calls pluralizer:

  • the words both directions share, with recommended and related
  • words ending in media after another letter, such as multimedia
  • for the plural only: people, media, trivia, and words ending in ware, such as software
  • for the singular only: data, radius, clothes and the other Doctrine singulars, and words ending in ss

The model macro formed default table names with its own pluralizer call, so fixing only str would have given #[model] struct Feedback a feedbacks table while constrained() pointed at feedback. The word lists and the per-word plural/singular now live in a small internal crate, laravel-rust-inflect (in macros/inflect, beside macro-support, with no dependency but pluralizer). laravel-rust-core and laravel-rust-model-macros both call it, so a model's table, constrained() and resource route parameters agree. GRAPH in tests/workspace_layout.rs lists the new crate.

The sea bass and social media patterns span two words, so they're left out, because inflect only looks at the last word.

lens: the same check fixes one irregular word. pluralizer takes lens for a plural, so "lens".plural() stayed lens and "lenses".singular() gave lense. A Lens model got a lens table and a lenses resource route a {lense} parameter. Laravel gives lenses and lens. I compared both inflectors over about 75,000 English words ending in s, using Doctrine run in PHP. lens was the only common noun that pluralizer left unchanged where Laravel pluralizes it, so it's one entry in an IRREGULAR table, kept in the word's case.

Breaking change: default tables and resource route parameters named after these words change, such as a Feedback model's table going from feedbacks to feedback, and {specie} becoming {species}. The lists follow Doctrine exactly, including nouns many applications count, such as food, art, travel, talent and emoji. If you'd rather keep those countable, I can trim the shared list to the words that are uncountable in everyday English. It lives in one place now, so trimming is a one-line change per word.

Tests: new cases in str::inflect, laravel-rust-inflect and the model macro's table test (Feedback, UserFeedback, Species, ContactLens) cover the shared words, words in snake and studly names, the plural-only and singular-only words, and that both lists stay sorted for the binary search. 15 of them fail without the change. cargo fmt --check and cargo clippy -p laravel-rust-core --all-targets --all-features -- -D warnings pass. The workspace --lib tests and the http, validation and database suites give the same results as on 0.x. I also ran every job from ci.yml on Linux with PostgreSQL, MySQL, MariaDB, Redis, ElasticMQ and MinIO: fmt, clippy, the minimal-features check, the unit and doc tests, and the core, testing_attribute, database, http and queue suites with --include-ignored all pass.

@zsnakeee
zsnakeee changed the base branch from main to 0.x December 3, 2026 01:49
@taylorotwell taylorotwell added bug p3 Priority 3: lowest labels Dec 3, 2026 — with Amp for GitHub

Copy link
Copy Markdown
Member

This is an automated, agent-powered review.

Confirmed. plural and singular hand every word to pluralizer, so "money".plural() is monies, "feedback".plural() is feedbacks, and "data".singular() is datum. An application hits this through foreign_id("feedback_id").constrained(), which references a feedbacks table, and through resource routes, where Route::resource("species", ..) names its parameter {specie}.

  • Checking the last word against the uncountable lists in inflect, before pluralizer runs, is the right place for str. It misses one caller with the same cause, though: #[model] forms a model's default table name at compile time with its own pluralizer call in macros/model/src/model.rs, so #[model] struct Feedback still gets the feedbacks table while constrained() now points at feedback. Today the two agree; with this PR they disagree for every word in the lists.
  • Fixing that means the lists live where both laravel-rust-core and the model macro can read them, such as a small shared inflection crate. That's a crate-structure decision, so I've left it for a maintainer rather than pushing it here.
  • This is a breaking change: tables and route parameters named after these words change, such as feedbacks, foods, travels, emojis, and arts, and {specie} becomes {species}. The lists include nouns many applications treat as countable, such as food, art, travel, talent, and emoji, so it's worth deciding how much of the list to keep alongside the breakage.
  • This conflicts with Choose a word's plural or singular from a count #470 only where both add tests at the end of inflect.rs's test module, so both can land in either order. Pluralize words that end in a digit #587 and Keep word breaks before non-ASCII words in snake and kebab case #596 merge cleanly with it.

Thanks for your contribution, a human review will follow shortly.

@zsnakeee

zsnakeee commented Dec 3, 2026

Copy link
Copy Markdown
Author

Thanks for the review. I pushed 3a5ae51 for the model macro point:

  • The word lists and the per-word plural/singular moved into a small internal crate, laravel-rust-inflect (macros/inflect, beside macro-support, depending only on pluralizer). laravel-rust-core's str and #[model]'s default table name both call it, so #[model] struct Feedback gets feedback, the same table foreign_id("feedback_id").constrained() points at. The macro's table test now covers Feedback, UserFeedback and Species, and GRAPH in tests/workspace_layout.rs lists the new crate.
  • On the breaking change: I added a note to the description. The lists follow Doctrine exactly, so they include food, art, travel, talent and emoji. If you'd rather keep everyday countable nouns countable, tell me which and I'll trim them. They live in one place now.

Every job from ci.yml passes on Linux against PostgreSQL, MySQL, MariaDB, Redis, ElasticMQ and MinIO.

plural and singular passed every word to the pluralizer crate, which
inflects many words that Laravel leaves alone: "money" became "monies",
"feedback" became "feedbacks" and "species" became "specie". The
doc comment already says uncountable words stay as they are.

The words now come from Laravel's Pluralizer ("recommended", "related")
and Doctrine's English inflector, which Laravel uses for the rest.
after the previous commit #[model] struct Feedback still got a feedbacks
table while foreign_id("feedback_id").constrained() pointed at feedback.

The plural and singular of a word, with the uncountable lists, now live
in a small laravel-rust-inflect crate that laravel-rust-core and the
model macros both use, so a model's table and the keys that point to it
agree.
pluralizer takes "lens" for a plural, so "lens".plural() stayed "lens"
and "lenses".singular() gave "lense". A Lens model got a lens table and
a lenses resource route a {lense} parameter. Laravel gives "lenses" and
"lens", so the shared inflector now has an irregular entry for it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug p3 Priority 3: lowest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants