How to disable Plural suffix?

Viewed 2351

Collection Types List does not list collectionName

API name is not "collection name" instead it is "Display Name" of Created collection type.

How to control Plural suffix?

Is there any way to define new irregular rule for pluralize utility?

pluralize.plural('irregular') //=> "irregulars"

I can not create content types other than English. It just adds it's own suffix, it makes i18n impossible.

Steps to reproduce the behavior

  1. Go to 'Content-Types Builder'
  2. Click on 'Create new collection type'
  3. Enter "araba" (a non-english word) to 'Display name'
  4. Enter "arabalar" (plural non-english word) to 'Collection name' under 'Advanced Settings'
  5. Check out left menu it does not display collectionName instead it displays API name

Expected behavior

IT SHOULD BE "arabalar" not "arabas" which was entered as collection name

Screenshots

singular plural

"arabalar" is plural of "araba" not "arabas"

wrong

System

  • Node.js version: v12.16.1
  • yarn version: 1.22.4
  • Strapi version: v3.0.0-beta.19.3
  • Database: sqlite
  • Operating system: windows
4 Answers

It's not possible to disable pluralization, but there is a workaround:

  1. Open file api\araba\models\araba.settings.json (araba is your API name)
  2. Add key displayName to info part of the

    "info": {
       "name": "Araba",
       "displayName": "arabalar"
     },

  1. create a file admin/src/components/LeftMenuLinkSection/index.js
  2. copy into it the contents of file node_modules/strapi-admin/admin/src/components/LeftMenuLinkSection/index.js
  3. Change this

   <LeftMenuLink
     location={location}
     key={index}
     iconName={link.icon}
     label={link.label}
     destination={getLinkDestination(link)}
   /> 

to this

       <LeftMenuLink
         location={location}
         key={index}
         iconName={link.icon}
         label={link.schema && link.schema.info.displayName ? link.schema.info.displayName : link.label}
         destination={getLinkDestination(link)}
        />

and yarn strapi build

The correct (and simplest) solution IMHO can be found in this Strapi issue: https://github.com/strapi/strapi/issues/8915#issuecomment-748436263. I'll simply report it:

I actually just figured out a more simple way to solve this issue.

I looked trough the code and found that this package: https://www.npmjs.com/package/pluralize is used for the pluralization. It has a build in method to add new rules. So what I did, is that I added the word/words from my local language (danish), which are getting translated wrong in this file: /config/functions/bootstrap.js which is executed before the app starts.

Like this:

'use strict';

const pluralize = require('pluralize')

/**
 * An asynchronous bootstrap function that runs before
 * your application gets started.
 *
 * This gives you an opportunity to set up your data model,
 * run jobs, or perform some special logic.
 *
 * See more details here: https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/configurations.html#bootstrap
 */

module.exports = () => {
    // Add danish plural versions of collection names
    pluralize.addPluralRule('side', 'sider')
    pluralize.addPluralRule('aktivitet', 'aktiviteter')  }; 

And then just let the server restart.

It's not possible to disable pluralization in Strapi.

the solution described above does not work in strapi version 3. In version 3.x you have to do it like this:

  1. extends your Model with "displayName", open the file api\{model}\models\{model}.settings.json and add a new attribute

    "info": { "name": "xy", "displayName": "Display Name" }
    
  2. create a new file under admin\src\containers\LeftMenu\utils\generateModelsLinks.js (copy&paste the original file from node_modules\strapi-admin\admin\src\containers\LeftMenu\utils)

  3. change the line (11) from

    label: link.info.label
    

    to

    label: link.info && link.info.displayName ? link.info.displayName
    
Related