작가:
    생성:2026-06-12마지막 업데이트:2026-06-26

    변형

    변형은 동일한 사전 key를 공유하지만 각각 다른 variant 값을 갖는 콘텐츠 파일의 집합입니다. Intlayer는 useIntlayer에 전달된 셀렉터에 따라 적절한 파일을 제공합니다.

    variant 값은 두 가지 형태를 가질 수 있습니다:

    • 문자열 — 단일 이름 지정 대안(A/B 테스트, 시즌 배너, 기능 플래그).
    • 객체 — 필드 집합으로 주소가 지정되는 구조화된 판별자(CMS 레코드, 사용자별 콘텐츠, 불투명한 ID로 키가 지정된 모든 콘텐츠). 객체 전체가 정체성입니다. 항목을 해결하려면 셀렉터가 동일한 객체를 제공해야 합니다.
    객체 형태는 이전의 meta 필드를 대체합니다. 이전에 meta: { id, … }를 작성했던 모든 곳에서 variant: { id, … }를 작성하고 { variant: { id, … } }로 선택하세요.

    이름 지정(문자열) 변형

    각 파일은 하나의 이름 지정 대안을 나타냅니다. variant를 생략하거나("default"로 설정하면) 폴백으로 표시됩니다.

    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: "fr",});

    객체(구조화) 변형

    객체 변형은 variant 필드에 선언된 임의의 키-값 쌍 집합으로 콘텐츠의 주소를 지정합니다 — 이를 통해 CMS 레코드, 사용자별 콘텐츠, 또는 키가 불투명한 ID인 모든 콘텐츠를 모델링할 수 있습니다. 객체 전체가 정체성입니다. 항목이 해결되려면 셀렉터가 동일한 객체를 제공해야 합니다.

    product.abc.content.ts
    import { t, type Dictionary } from "intlayer";
    
    const dictionary = {
      key: "product",
      variant: { id: "prod_abc", userId: "user_123" },
      content: {
        name: t({ en: "Widget Pro", fr: "Widget Pro" }),
        description: t({ en: "The best widget.", fr: "Le meilleur widget." }),
      },
    } satisfies Dictionary;
    
    export default dictionary;
    product.abcd.content.ts
    import { t, type Dictionary } from "intlayer";
    
    const dictionary = {
      key: "product",
      variant: { id: "prod_abcd", userId: "user_123" },
      content: {
        name: t({ en: "Widget Lite", fr: "Widget Lite" }),
        description: t({ en: "A lighter option.", fr: "Une option plus légère." }),
      },
    } satisfies Dictionary;
    
    export default dictionary;

    객체 변형 사용

    일치하는 객체를 variant에 전달하세요. 사전에 선언된 모든 필드를 제공해야 하며 동일해야 합니다. 그렇지 않으면 결과는 null입니다. 필드 순서는 중요하지 않습니다.

    Product.tsx
    import { useIntlayer } from "react-intlayer";
    
    export const Product = ({
      productId,
      userId,
    }: {
      productId: string;
      userId: string;
    }) => {
      const content = useIntlayer("product", {
        variant: { id: productId, userId },
      });
    
      if (!content) return null;
    
      return <p>{content.description}</p>;
    };

    명시적 로케일과 함께

    tsx
    const content = useIntlayer("product", {  variant: { id: "prod_abc", userId: "user_123" },  locale: "fr",});

    누락된 필드 — 일치 없음

    ts
    // null 반환: `userId`가 누락되어 객체가 선언된 변형과 일치하지 않습니다const content = useIntlayer("product", { variant: { id: "prod_abc" } });

    로딩 모드

    객체 변형은 종종 지연 로드됩니다. 이를 제어하려면 사전에 importMode를 설정하세요:

    ts
    const dictionary = {
      key: "product",
      importMode: "fetch", // or "dynamic"
      variant: { id: "prod_abc", userId: "user_123" },
      content: { … },
    } satisfies Dictionary;
    
    export default dictionary;

    static, dynamic, fetch 모드에 대한 자세한 내용은 번들 최적화를 참조하세요.

    일반적인 사용 사례

    • 실험 키로 구동되는 A/B 카피 테스트
    • 시즌 또는 프로모션 배너
    • 기능 플래그 메시지
    • 로케일별 마케팅 캠페인
    • CMS에서 관리되는 제품별 마케팅 카피
    • 사용자별 또는 계정별 콘텐츠
    • 런타임에 불투명한 ID로 키가 지정된 모든 콘텐츠