Support For Gender-Based Conditional Content

by ADMIN 45 views

Current Behavior

Currently, intlayer supports locale-based content using key/value dictionaries, but does not support gender-based variations in messages. For example, welcoming users with the appropriate gender-specific phrase must be handled manually, often outside of the content layer, which defeats the purpose of centralized, declarative content.

There is no built-in method to define gender-specific variations like:

Welcome, sir // (male)
Welcome, ma’am // (female)
Welcome // (other/unspecified)

This limitation can lead to inconsistent formatting across languages and keys, making it challenging to manage and maintain content. Moreover, it requires developers to handle gender-specific variations manually, which can be time-consuming and prone to errors.

Expected Behavior

Provide a built-in utility (e.g., gender(...)) to declare gendered variations of content per locale, similarly to the existing translation structure.

New Example:

import { gender, type Dictionary } from 'intlayer';

const genderBasedContent = {
  key: 'helloworld',
  content: {
    greeting: gender({
      en: {
        male: 'Welcome, sir',
        female: 'Welcome, ma’am',
        other: 'Welcome',
      },
      fr: {
        male: 'Bienvenue, monsieur',
        female: 'Bienvenue, madame',
        other: 'Bienvenue',
      },
    }),
  },
} satisfies Dictionary;

export default genderBasedContent;

This allows:

  • Consistent formatting across languages and keys.
  • Centralized management of gendered variations.
  • Extensibility if more genders or variations are needed in the future.

Use Cases

  1. Personalized Greetings

    "Welcome, sir/ma’am" or "Bonjour, monsieur/madame" in onboarding flows or account dashboards.

  2. Transactional Emails or Messages

    "Your order has shipped, Mr. Dupont." vs. "Your order has shipped, Ms. Garcia."

  3. Gamified UIs or Stories

    Dynamic dialogues in games or interactive stories based on the user's selected gender.

Additional Considerations

  • Fallback to other if gender isn't specified.
  • Work with other nesting / enum / translation imbrication.

Feature Based on Community Feedback

This improvement is driven by valuable feedback from @ctjhoa. The addition of gender-based conditional content will enhance the overall user experience by providing a more personalized and inclusive experience.

Benefits of the Feature

  • Improved user experience: By providing a more personalized experience, users will feel more engaged and connected to the application.
  • Increased inclusivity: The feature will cater to users of all genders, making the application more accessible and welcoming.
  • Simplified content management: The centralized management of gendered variations will reduce the complexity of content management and make it easier to maintain.

Implementation Details

The implementation of the feature will involve the following steps:

  1. Add a new utility function: Create a new utility function gender() that will allow developers to declare gendered variations of content per locale.
  2. egrate with existing translation structure: Integrate the new utility function with the existing translation structure to ensure seamless integration.
  3. Test and validate: Thoroughly test and validate the feature to ensure it works as expected and does not introduce any bugs.

Frequently Asked Questions

We've received many questions about the new feature for supporting gender-based conditional content in intlayer. Below, we've compiled a list of frequently asked questions and answers to help clarify any doubts.

Q: What is the purpose of the new feature?

A: The new feature allows developers to declare gendered variations of content per locale, making it easier to manage and maintain content that is inclusive and personalized.

Q: How does the new feature work?

A: The new feature uses a utility function gender() that allows developers to specify gendered variations of content per locale. This function integrates with the existing translation structure, making it seamless to use.

Q: What are the benefits of the new feature?

A: The new feature provides several benefits, including:

  • Improved user experience: By providing a more personalized experience, users will feel more engaged and connected to the application.
  • Increased inclusivity: The feature will cater to users of all genders, making the application more accessible and welcoming.
  • Simplified content management: The centralized management of gendered variations will reduce the complexity of content management and make it easier to maintain.

Q: How do I implement the new feature?

A: To implement the new feature, you'll need to:

  1. Add a new utility function gender() to your code.
  2. Integrate the new utility function with the existing translation structure.
  3. Test and validate the feature to ensure it works as expected and does not introduce any bugs.

Q: Can I use the new feature with other nesting/enumeration/translation imbrication?

A: Yes, the new feature is designed to work with other nesting/enumeration/translation imbrication. You can use it in conjunction with other features to create a more comprehensive and inclusive content management system.

Q: What happens if I don't specify a gender?

A: If you don't specify a gender, the feature will default to the other variation.

Q: Can I add more genders or variations in the future?

A: Yes, the new feature is designed to be extensible. You can easily add more genders or variations in the future by modifying the gender() utility function.

Q: How does the new feature impact performance?

A: The new feature is designed to be efficient and does not impact performance. It uses a simple and lightweight approach to manage gendered variations, making it easy to integrate and use.

Q: Is the new feature compatible with existing code?

A: Yes, the new feature is designed to be backward compatible with existing code. You can use it with your existing code without any issues.

Conclusion

The new feature for supporting gender-based conditional content in intlayer provides a more comprehensive and inclusive content management system. By answering frequently asked questions, we hope to have clarified any doubts and provided a better understanding of the feature. If you have any further questions or concerns, please don't hesitate to reach out.