ICU Select for Gender-Aware Messages
Use ICU select to create gender-aware messages that adapt pronouns and phrasing based on user preferences. Covers male, female, and non-binary inclusive patterns.
Detailed Explanation
Gender-Aware Messages with ICU Select
The select argument type in ICU MessageFormat lets you branch message content based on an arbitrary string value. The most common use case is gender-aware pronoun selection, but it works for any categorical variable.
Basic Gender Select
{gender, select,
male {He liked your photo.}
female {She liked your photo.}
other {They liked your photo.}
}
The other case is required and serves as the default when the provided value does not match any explicit case. For gender, other typically uses gender-neutral language.
Combining Select with Variables
Select cases can contain additional variable placeholders:
{gender, select,
male {{name} updated his profile.}
female {{name} updated her profile.}
other {{name} updated their profile.}
}
Note the double braces: the outer braces delimit the case content, and the inner {name} is a variable placeholder.
Beyond Binary Gender
Modern applications should support more than male/female. A comprehensive approach:
{gender, select,
male {He}
female {She}
nonbinary {They}
other {They}
}
The other fallback ensures the message always renders even if an unexpected value is provided.
Select for Non-Gender Categories
Select is not limited to gender. Use it for any categorical distinction:
{status, select,
active {Your account is active.}
suspended {Your account has been suspended. Contact support.}
pending {Your account is pending verification.}
other {Your account status is unknown.}
}
Translation Considerations
When using select, translators see the full context of each branch, which helps them produce natural translations. In languages where the entire sentence structure changes based on gender (like French, German, or Arabic), the select argument gives translators full control over each variant without requiring code changes.
Nesting Select with Plural
For complex messages, select and plural can be nested:
{gender, select,
male {He has {count, plural, one {# friend} other {# friends}}.}
female {She has {count, plural, one {# friend} other {# friends}}.}
other {They have {count, plural, one {# friend} other {# friends}}.}
}
Note how the verb also changes ("has" vs. "have") in the other case -- this is exactly why select is essential for natural-sounding translated text.
Use Case
UI developers building inclusive applications that need to adapt pronoun usage and gendered language in translated messages, particularly for social features like notifications and profile updates.