שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
היסטוריית גרסאות
- "Init history"v8.8.04.5.2026
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתאם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודהעתקת ה-Markdown של המסמך ללוח
Plural Content / Plural in Intlayer
How Plural Works
In Intlayer, plural content is achieved through the plural function, which maps CLDR plural categories, zero, one, two, few, many, other, to their corresponding content. The correct category is selected automatically based on the active locale and a count value, using the platform's built-in Intl.PluralRules API.
Unlike enu, which selects content based on numeric ranges you define yourself, plural delegates the selection to CLDR rules. This is what makes it scalable to languages with complex pluralization rules, such as Russian, Polish, Arabic, or Welsh, without having to hand-write modulo logic.
When to Use plural vs enu
פתיחת הטבלה בחלון כדי לראות את כל תוכן הנתונים בבירור
| Use case | Helper |
|---|---|
| Locale-aware grammatical plural forms (one apple / two apples / 5 яблок) | plural |
Custom numeric ranges (<5, >=10) or non-CLDR buckets | enu |
If you only target English (which has just one / other), either works. For any language with few / many / two distinctions, prefer plural.
Setting Up Plural Content
To set up plural content in your Intlayer project, create a content module that uses the plural helper. The other category is required and is used as the fallback when a locale doesn't define a more specific category.
העתקת הקוד ללוח
import { plural, t, type Dictionary } from "intlayer";
const openingsContent = {
key: "total_openings",
content: {
totalOpenings: t({
en: plural({
one: "{{count}} opening",
other: "{{count}} openings",
}),
ru: plural({
one: "{{count}} вакансия",
few: "{{count}} вакансии",
many: "{{count}} вакансий",
other: "{{count}} вакансий",
}),
}),
},
} satisfies Dictionary;
export default openingsContent;
The supported categories are
zero,one,two,few,many,other. You only need to declare the categories your target language uses, Intlayer falls back tootherwhen no specific category matches.The
{{count}}placeholder is automatically replaced with the count you pass at runtime. You can include other placeholders too (see Custom placeholders below).
Using Plural Content
To use plural content inside a React component, retrieve it via the useIntlayer hook and call it with a count. The active locale and the count are combined to pick the matching CLDR category.
העתקת הקוד ללוח
import type { FC } from "react";
import { useIntlayer } from "react-intlayer";
const OpeningsComponent: FC<{ count: number }> = ({ count }) => {
const { totalOpenings } = useIntlayer("total_openings");
return (
<div>
<p>{totalOpenings(count)}</p>
</div>
);
};
export default OpeningsComponent;
To use plural content in Next.js Client Components, retrieve it via the useIntlayer hook and call it with a count. Here's an example:
העתקת הקוד ללוח
"use client";
import type { FC } from "react";
import { useIntlayer } from "next-intlayer";
const OpeningsComponent: FC<{ count: number }> = ({ count }) => {
const { totalOpenings } = useIntlayer("total_openings");
return (
<div>
<p>{totalOpenings(count)}</p>
</div>
);
};
export default OpeningsComponent;
To use plural content in Vue components, retrieve it via the useIntlayer hook and call it with a count. Here's an example:
העתקת הקוד ללוח
To use plural content in Svelte components, retrieve it via the useIntlayer hook and call it with a count. The store is accessed with $. Here's an example:
העתקת הקוד ללוח
To use plural content in Preact components, retrieve it via the useIntlayer hook and call it with a count. Here's an example:
העתקת הקוד ללוח
import type { FC } from "preact";
import { useIntlayer } from "preact-intlayer";
const OpeningsComponent: FC<{ count: number }> = ({ count }) => {
const { totalOpenings } = useIntlayer("total_openings");
return (
<div>
<p>{totalOpenings(count)}</p>
</div>
);
};
export default OpeningsComponent;
To use plural content in SolidJS components, retrieve it via the useIntlayer hook and call it with a count. Here's an example:
העתקת הקוד ללוח
import type { Component } from "solid-js";
import { useIntlayer } from "solid-intlayer";
const OpeningsComponent: Component<{ count: number }> = (props) => {
const { totalOpenings } = useIntlayer("total_openings");
return (
<div>
<p>{totalOpenings(props.count)}</p>
</div>
);
};
export default OpeningsComponent;
To use plural content in Angular components, retrieve it via the useIntlayer hook and call it with a count. Here's an example:
העתקת הקוד ללוח
To use plural content with vanilla-intlayer, retrieve it via the useIntlayer hook and call it with a count. Here's an example:
העתקת הקוד ללוח
import { installIntlayer, useIntlayer } from "vanilla-intlayer";
installIntlayer();
const content = useIntlayer("total_openings").onChange((newContent) => {
document.getElementById("openings")!.textContent =
newContent.totalOpenings(5);
});
// Initial render
document.getElementById("openings")!.textContent = content.totalOpenings(5);
Custom placeholders
Plural strings can include placeholders other than {{count}}. Pass them in the object form alongside count:
העתקת הקוד ללוח
import { plural, type Dictionary } from "intlayer";
const inboxContent = {
key: "inbox_summary",
content: {
summary: plural({
one: "{{name}}, you have {{count}} new message",
other: "{{name}}, you have {{count}} new messages",
}),
},
} satisfies Dictionary;
export default inboxContent;
העתקת הקוד ללוח
const { summary } = useIntlayer("inbox_summary");
summary({ count: 1, name: "Alice" });
// → "Alice, you have 1 new message"
summary({ count: 7, name: "Alice" });
// → "Alice, you have 7 new messages"
CLDR Categories at a Glance
Different languages use different subsets of the CLDR categories. A few common cases:
פתיחת הטבלה בחלון כדי לראות את כל תוכן הנתונים בבירור
| Language | Categories used |
|---|---|
English (en) | one, other |
French (fr) | one, many, other |
Russian (ru) | one, few, many, other |
Polish (pl) | one, few, many, other |
Arabic (ar) | zero, one, two, few, many, other |
| Japanese / Chinese | other only |
You don't need to memorize this, declare the categories you have translations for, and Intlayer will fall back to other when needed.
Limitation
In comparison to other nodes, plural cannot be imbricated with children nodes yet.
Example:
Valid:
העתקת הקוד ללוח
Invalid:
העתקת הקוד ללוח
Additional Resources
For more detailed information on configuration and usage, refer to the following resources:
These resources offer further insights into the setup and usage of Intlayer across various environments and frameworks.
