Автор:
    Дата створення:2025-07-27Останнє оновлення:2025-07-27

    Гендерно-орієнтований контент / Гендер в 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, створіть модуль контенту, який містить ваші визначення для конкретних гендерів. Нижче наведені приклади в різних форматах.

    **/*.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 у різних середовищах та фреймворках.