작가:
    생성:2025-07-27마지막 업데이트:2025-07-27

    성별 기반 콘텐츠 / Intlayer의 성별

    성별 작동 방식

    Intlayer에서는 gender 함수를 통해 성별 기반 콘텐츠를 구현합니다. 이 함수는 특정 성별 값('male', 'female')을 해당하는 콘텐츠에 매핑합니다. 이 방식을 통해 주어진 성별에 따라 동적으로 콘텐츠를 선택할 수 있습니다. React Intlayer 또는 Next Intlayer와 통합하면, 런타임에 제공된 성별에 따라 적절한 콘텐츠가 자동으로 선택됩니다.

    성별 기반 콘텐츠 설정

    Intlayer 프로젝트에서 성별 기반 콘텐츠를 설정하려면, 성별별 정의를 포함하는 콘텐츠 모듈을 생성하세요. 아래는 다양한 형식의 예시입니다.

    **/*.content.ts
    import { gender, type Dictionary } from "intlayer";
    
    const myGenderContent = {
      key: "my_key",
      content: {
        myGender: gender({
          male: "남성 사용자용 콘텐츠",
          female: "여성 사용자용 콘텐츠",
          fallback: "성별이 지정되지 않았을 때의 콘텐츠", // 선택 사항
        }),
      },
    } satisfies Dictionary;
    
    export default myGenderContent;
    만약 fallback이 선언되지 않았다면, 성별이 지정되지 않았거나 정의된 성별과 일치하지 않을 경우 마지막으로 선언된 키가 fallback으로 사용됩니다.

    React Intlayer에서 성별 기반 콘텐츠 사용하기

    To utilize gender-based content within a React component, import and use the useIntlayer hook from the react-intlayer package. This hook fetches the content for the specified key and allows you to pass in a gender to select the appropriate output.

    **/*.tsx
    import type { FC } from "react";
    import { useIntlayer } from "react-intlayer";
    
    const GenderComponent: FC = () => {
    const { myGender } = useIntlayer("my_key");
    
    return (
      <div>
        <p>
          {
            /* Output: my content for male users */
            myGender("male")
          }
        </p>
        <p>
          {
            /* Output: my content for female users */
            myGender("female")
          }
        </p>
        <p>
          {
            /* Output: my content for male users */
            myGender("m")
          }
        </p>
        <p>
          {
            /* Output: my content for female users */
            myGender("f")
          }
        </p>
        <p>
          {
            /* Output: my content when gender is not specified */
            myGender("")
          }
        </p>
        <p>
          {
            /* Output: my content when gender is not specified */
            myGender(undefined)
          }
        </p>
      </div>
    );
    };
    
    export default GenderComponent;

    추가 자료

    설정 및 사용법에 대한 자세한 정보는 다음 자료를 참조하세요:

    이 자료들은 다양한 환경과 프레임워크에서 Intlayer의 설정 및 사용에 대한 추가적인 통찰을 제공합니다.