Penulis:
    Dibuat:2025-07-27Terakhir diperbarui:2025-07-27

    Konten Berdasarkan Gender / Gender di Intlayer

    Cara Kerja Gender

    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;

    Menyiapkan Konten Berdasarkan Gender

    Untuk menyiapkan konten berdasarkan gender dalam proyek Intlayer Anda, buat modul konten yang mencakup definisi spesifik gender Anda. Berikut adalah contoh dalam berbagai format.

    **/*.content.ts
    import { gender, type Dictionary } from "intlayer";
    
    const myGenderContent = {
      key: "my_key",
      content: {
        myGender: gender({
          male: "konten saya untuk pengguna laki-laki",
          female: "konten saya untuk pengguna perempuan",
          fallback: "konten saya ketika gender tidak ditentukan", // Opsional
        }),
      },
    } satisfies Dictionary;
    
    export default myGenderContent;
    Jika tidak ada fallback yang dideklarasikan, kunci terakhir yang dideklarasikan akan digunakan sebagai fallback jika gender tidak ditentukan atau tidak cocok dengan gender yang didefinisikan.

    Menggunakan Konten Berbasis Gender dengan 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;

    Sumber Daya Tambahan

    Untuk informasi lebih rinci tentang konfigurasi dan penggunaan, lihat sumber daya berikut:

    Sumber daya ini menawarkan wawasan lebih lanjut tentang pengaturan dan penggunaan Intlayer di berbagai lingkungan dan kerangka kerja.