Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
YouTube Security VideosMicrosoft Mechanics: A Copilot Agent Writes the Status Report(23.09.2026 um 03:30 Uhr)
Sichere ProgrammierungOpenTelemetry in the GitHub Copilot app(23.09.2026 um 04:14 Uhr)
Sichere ProgrammierungMy Introduction:(23.09.2026 um 03:53 Uhr)
Sichere ProgrammierungAgentWallex: Content Day (Articles going live)(23.09.2026 um 04:00 Uhr)
Sichere ProgrammierungYour Low-Code Platform Is Fast Until a Customer Builds One Real Table(23.09.2026 um 04:11 Uhr)
YouTube Security VideosMicrosoft Mechanics: A Copilot Agent Writes the Status Report(23.09.2026 um 03:30 Uhr)
Sichere ProgrammierungOpenTelemetry in the GitHub Copilot app(23.09.2026 um 04:14 Uhr)
Sichere ProgrammierungMy Introduction:(23.09.2026 um 03:53 Uhr)
Sichere ProgrammierungAgentWallex: Content Day (Articles going live)(23.09.2026 um 04:00 Uhr)
Sichere ProgrammierungYour Low-Code Platform Is Fast Until a Customer Builds One Real Table(23.09.2026 um 04:11 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Pluralization 101 in React

What is pluralization? I often encounter apps that display awkward messages like: You have 1 new message(s) This is a telltale sign of a developer who hasn't thought carefully about user experience. React apps often need…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!




What is pluralization?



I often encounter apps that display awkward messages like:




You have 1 new message(s)






This is a telltale sign of a developer who hasn't thought carefully about user experience.



React apps often need pluralization — for notification counts, list lengths, or search results. And it's not that hard to get pluralization right, especially if you only need your app in English. But there are plenty of bad practices new developers fall into, especially for multilingual interfaces.






Hard-coded plurals



Many projects — including surprisingly large and important ones — hard-code plural logic.




export default function Example({ n }) {
return (
<p>
Displaying {n} item{ n === 1 ? "" : "s" }
</p>
)
}






But pluralization is often more complex than just adding an "s" to the end of a word. Some nouns have irregular plural forms, like "child" and "children". Sometimes, other parts of the sentence may also need to change to reflect the changed word, like "is" and "are" changing depending on the count.



The table below illustrates some common scenarios:




























Scenario Examples Notes
Viewer count "1 person is watching"
"2 people are watching"
Irregular noun ("person" → "people") and verb changes needed.
Item deletion "Delete this message?"
"Delete these 2 messages?"
Demonstrative changes ("this" vs. "these") plus noun pluralization.
Search results "No results"
"1 result found"
"2 results found"
Different phrasing for zero, one, and multiple results.


Using conditional expressions quickly becomes unwieldy.



And it becomes a nightmare when you need to ship your app in other languages. What works for English often breaks completely in languages like Polish or Arabic, which have entirely different rules for handling quantities.









English pluralization



In English, using the right plurals in your app is usually straightforward.



For simple noun pluralization, write a utility function:




export function pluralize(
count: number,
singular: string,
plural: string = singular + "s"
) {
return `${count === 1 ? singular : plural}`;
}






Now there is a single function for handling all our plural logic,

and it works for irregular plurals too:




pluralize(2, "user") // "users"
pluralize(2, "person", "people") // "people"
pluralize(2, "child", "children") // "children"






But what if you need more complicated logic, like:




"No one is watching"
"1 person is watching"
"2 people are watching"






At this stage, you should think seriously about a low-maintainence internationalization ("i18n") library.



Although developers often think that i18n libraries are only for multilingual interfaces, they can be very useful for plural and variable formatting even in single-language applications.



There are plenty of React i18n libraries, including one that I wrote, gt-react (or gt-next if you're using Next.js). Displaying an English plural using gt-react is super simple:




import { Plural } from 'gt-react'

function Example({ count }) {
return (
<Plural
n={count}
zero={"No one is watching"}
one={`${count} person is watching`}
>
{count} people are watching
</Plural>
)
}






UI is conditionally rendered based on the value of n.



Most libraries use JavaScript's Intl object to decide which plural form to display. This means that in English, you would use the name "one" to refer to a singular and "other" to refer to a plural.



Using a library here is best practice even for English-only applications, and makes future internationalization much easier.









Internationalization (i18n) and plurals



Shipping a multilingual interface makes displaying plurals much more complicated.




  • In Arabic, nouns have different forms depending on whether there are zero, one, two, or many of them

  • In Spanish, German, and Italian, large numbers use periods instead of commas, so 1,000,000 becomes 1.000.000

  • In Hindi, digits are grouped in pairs, so 1,000,000 would become 10,00,000



For an internationalized app, you should use a dedicated library which will have its own documentation on how to handle plurals and number formatting.






Formatting numbers for different languages



You can also use the Intl object to format numbers.

The easiest way to do this is with the built-in toLocaleString() method.



By default, this will use the runtime's current locale:




const n = 1000000;
n.toLocaleString() // displays 1,000,000 when the runtime locale is "en-US" (American English)
n.toLocaleString("de") // 1.000.000 because the locale has been specified as "de" (German)






You could also define or import a <Num> component which relies on Intl.NumberFormat under the hood.




import { Num } from 'gt-react'

// displays 1,000,000 when the language is "en-US"
// displays 1.000.000 when the language is "de"
// displays 10,00,000 when the language is "hi"
export default function Example() {
return <Num>1000000</Num>;
}









Displaying alternate plural forms



The six plural forms supported by JavaScript's Intl object are: zero, one, two, few, many, other. Although English uses only one ("singular") and other ("plural"), languages like Arabic and Polish have more than just these two forms.



For example, an English-speaking user might expect:




"No one is watching"
"1 person is watching"
"2 people are watching"






Whereas an Arabic-speaking user might expect different expressions for singular, dual (when the count is exactly two things), and small and large plural forms:




"لا أحد يشاهد"
"1 شخص يشاهد"
"2 شخصان يشاهدان"
"3 أشخاص يشاهدون"
"11 شخصاً يشاهدون"






This is where an internationalization library becomes essential. Every language has its own logic for when and how to display plurals, so it's better to rely on a dedicated library to get it right.



A good internationalization library will do two things:




  1. Decide which plural form (one, many, other, etc.) to use based on the locale

  2. Locate the translation in the right language which corresponds to that form



If you already have an internationalization library, check their docs for information on plural formatting. Almost all libraries have dedicated documentation on rendering plurals.






gt-react



If you don't already have an internationalization library, consider gt-react!



gt-react's <Plural> component:




  • Is a simple, functional way to render plurals correctly

  • Works natively with the <Num> formatting component

  • Works natively with the <T> translation component, which integrates with GT's free translation service to generate plural forms automatically



Putting all the building blocks together, we have a complete multilingual interface:




import { T, Plural, Num } from 'gt-react'

// Works out of the box in 100+ languages
function Example({ count }) {
return (
<T>
<Plural
n={count}
zero={"No one is watching"}
one={
<><Num>{count}</Num> person is watching</>
}
>
<Num>{count}</Num> people are watching
</Plural>
</T>
)
}






Interested in learning more? Check out the docs on how to set up gt-react or gt-next.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Pluralization 101 in React

Thematisch verwandte Begriffe: Pluralization, React · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-17636 | IBM Financial Transaction Manager (FTM) for RedHat OpenShift could allow…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick