Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Release of the variants feature"v9.0.012/06/2026
The content of this page was translated using an AI.
See the last version of the original content in EnglishIf you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy doc Markdown to clipboard
Variants
A variant is a set of content files that share the same dictionary key but each carry a different variant name. Intlayer serves the appropriate file based on the selector passed to useIntlayer.
Declaring variants
Each file represents one named alternative. Omitting variant (or setting it to "default") marks it as the fallback.
Copy the code to the clipboard
import { t, type Dictionary } from "intlayer";
const dictionary = {
key: "hero-banner",
variant: "default",
content: {
headline: t({
en: "Build faster with Intlayer",
fr: "Développez plus vite avec Intlayer",
}),
cta: t({ en: "Get started", fr: "Commencer" }),
},
} satisfies Dictionary;
export default dictionary;Copy the code to the clipboard
import { t, type Dictionary } from "intlayer";
const dictionary = {
key: "hero-banner",
variant: "black_friday",
content: {
headline: t({
en: "50 % off — today only",
fr: "−50 % — aujourd'hui seulement",
}),
cta: t({ en: "Shop now", fr: "Acheter maintenant" }),
},
} satisfies Dictionary;
export default dictionary;Consuming variants
Default variant
Copy the code to the clipboard
import { useIntlayer } from "react-intlayer";
export const Hero = () => {
const { headline, cta } = useIntlayer("hero-banner");
// → default variant
return (
<section>
<h1>{headline}</h1>
<a>{cta}</a>
</section>
);
};Named variant
Copy the code to the clipboard
const { headline, cta } = useIntlayer("hero-banner", { variant: "black_friday",});Named variant with explicit locale
Copy the code to the clipboard
const content = useIntlayer("hero-banner", { variant: "black_friday", locale: "en-GB",});Typical use-cases
- A/B copy tests driven by an experiment key
- Seasonal or promotional banners
- Feature-flagged messaging
- Locale-specific marketing campaigns