I’ve used Rails many years ago and like the idea using singular and plural names. And the scaffold-command performs well in that regard.
But plural in English is often different than in say Norwegian and Danish. As an example I’m writing an application that keeps track of equipment, person assigned to, type etc. Very basic and a good fit for me to become acquainted with RWjs.
The singular Unit becomes Units in English. Unit in Norwegian is Enhet (singular) and Enheter (plural). After I ran the scaffold-command I searched any occurenses of Enhets and changed to Enheter to make it correct.
Would it be possible to add a flag to the scaffold-command to indicate what the plural ending is if it differs from the s-ending?
@kometen this is an important case! Thanks for opening the discussion. The short answer --> yes, it would be possible, but I’m not sure how tedious the implementation would be.
Here’s the generator code: https://github.com/redwoodjs/redwood/blob/master/packages/cli/src/commands/generate/scaffold/scaffold.js
Effectively, plural words are being handled by this NPM package: https://www.npmjs.com/package/pluralize
I took a look, and pluralize does have a list of “Irregular” and “Ignore” rules, but it only supports English: https://github.com/blakeembrey/pluralize/blob/master/pluralize.js
Reactions/thoughts after taking a look at this code?
Thank you for the links. I’ll take a look and see if I can kick the tyres.
Interesting idea, however I’d voice some doubts about feasibility: some languages have more than one form of plural ( to confirm but I heard that russian would have 4 different types of plural… ). How will we prioritize who gets what?
Valid point. My idea is to specify and ending if it differs from the default s-ending. Most plural endings in Norwegian and Danish append an e or er.
I guess what you could do is create your own
pluralize.js and using Babel Config/TSConfig/Webpack Config you could map
pluralize to that file.
If you put it in a folder and slap in a package.json you could even just use it as a file dependency I think?:
How about adding an optional parameter to the
cli command, like:
yarn rw g scaffold bacterium --plural=bacteria
Then the pluralization can be correct in any language, even if not correct by default.
@mgreenbe Conceptually this would be fantastic. Not sure how well this would play with the current packages we’re using, but if I recall correctly it might be possible.
@rob Looping you in here to see if it generates any ideas.
Also, as a bit of an update, did we ever tell you all about the time Tom was doing a live demo and “Pokemon” blew the whole thing up??
Someone suggested adding custom pluralization rules to
redwood.toml which sounded great to me, but I have no idea what goes into reading those in and turning them into function calls on
pluralize to set them up:
// Example of new plural rule:
pluralize.plural('regex') //=> "regexes"
pluralize.plural('regex') //=> "regexii"
// Example of new singular rule:
pluralize.singular('singles') //=> "single"
pluralize.singular('singles') //=> "singular"
// Example of new irregular rule, e.g. "I" -> "we":
pluralize.plural('irregular') //=> "irregulars"
pluralize.plural('irregular') //=> "regular"
// Example of uncountable rule (rules without singular/plural in context):
pluralize.plural('paper') //=> "papers"
pluralize.plural('paper') //=> "paper"
// Example of asking whether a word looks singular or plural:
pluralize.isPlural('test') //=> false
pluralize.isSingular('test') //=> true