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

    वेरिएंट (Variants)

    एक वेरिएंट (variant) सामग्री फ़ाइलों का एक सेट है जो एक ही डिक्शनरी कुंजी (key) साझा करते हैं लेकिन प्रत्येक में एक अलग variant नाम होता है। Intlayer useIntlayer को दिए गए चयनकर्ता के आधार पर उपयुक्त फ़ाइल प्रस्तुत करता है।

    वेरिएंट घोषित करना

    प्रत्येक फ़ाइल एक नामित विकल्प का प्रतिनिधित्व करती है। variant फ़ील्ड को छोड़ने (या इसे "default" पर सेट करने) से यह डिफ़ॉल्ट (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;

    वेरिएंट का उपयोग करना

    डिफ़ॉल्ट वेरिएंट

    Hero.tsx
    import { useIntlayer } from "react-intlayer";
    
    export const Hero = () => {
      const { headline, cta } = useIntlayer("hero-banner");
      // → डिफ़ॉल्ट वेरिएंट
    
      return (
        <section>
          <h1>{headline}</h1>
          <a>{cta}</a>
        </section>
      );
    };

    नामित वेरिएंट

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

    स्पष्ट भाषा विकल्प के साथ नामित वेरिएंट

    tsx
    const content = useIntlayer("hero-banner", {  variant: "black_friday",  locale: "hi",});

    विशिष्ट उपयोग के मामले

    • एक परीक्षण कुंजी द्वारा संचालित A/B प्रतिलिपि परीक्षण
    • मौसमी या प्रचार बैनर
    • फीचर-फ़्लैग्ड मैसेजिंग
    • स्थानीय बाजार के विशिष्ट अभियान