Author:
    Creation:2026-06-12Last update:2026-06-12

    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.

    hero-banner.content.ts
    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;
    hero-banner.black-friday.content.ts
    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

    Hero.tsx
    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

    tsx
    const { headline, cta } = useIntlayer("hero-banner", {  variant: "black_friday",});

    Named variant with explicit locale

    tsx
    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