Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Mechanism for adding default contexts #75

@marksteele

Description

@marksteele

So when dealing with things like gendered translations, the recommended approach is to leverage translation contexts.

It might look something like this (using lioness)

{ person.gender === "male" ? (
            <T
            message="Dear {{ name }}, there is one potato left"
            messagePlural="Dear {{ name }}, there are {{ count }} potatoes left"
            count={numPotatoes}
            name={person.name}
            context="male"
          />  
          )
            :
          (
            <T
            message="Dear {{ name }}, there is one potato left"
            messagePlural="Dear {{ name }}, there are {{ count }} potatoes left"
            count={numPotatoes}
            name={person.name}
            context="female"
            />  
          )        
      }

There is an obvious glaring problem with this approach, being that the component is duplicated simply because we want to be able to extract both contexts.

It would be great if we could pass in an array of contexts via config to apply to all extracted translation strings (overrideContext?)

The above code would then be:

            <T
            message="Dear {{ name }}, there is one potato left"
            messagePlural="Dear {{ name }}, there are {{ count }} potatoes left"
            count={numPotatoes}
            name={person.name}
            context={person.gender}
          />  
      }
// In the parser config: {...otherOptions, overrideContext: ['male', 'female'] }
// Would spit out two entries for that translation key, one for each context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions