ICU Selectで性別対応メッセージを作成
ICU selectを使用して、ユーザーの好みに基づいて代名詞や表現を適応させる性別対応メッセージを作成。男性、女性、ノンバイナリー対応のパターンをカバー。
Plural & Select
詳細な説明
ICU Selectによる性別対応メッセージ
ICU MessageFormatのselect引数型は、任意の文字列値に基づいてメッセージ内容を分岐させることができます。最も一般的なユースケースは性別対応の代名詞選択ですが、任意のカテゴリ変数に使用できます。
基本的な性別Select
{gender, select,
male {He liked your photo.}
female {She liked your photo.}
other {They liked your photo.}
}
otherケースは必須で、提供された値が明示的なケースにマッチしない場合のデフォルトとして機能します。性別の場合、otherは通常、性別中立的な言語を使用します。
Selectと変数の組み合わせ
Selectケースには追加の変数プレースホルダーを含めることができます:
{gender, select,
male {{name} updated his profile.}
female {{name} updated her profile.}
other {{name} updated their profile.}
}
バイナリー以外の性別
現代のアプリケーションは男性/女性以上をサポートすべきです。包括的なアプローチ:
{gender, select,
male {He}
female {She}
nonbinary {They}
other {They}
}
性別以外のカテゴリ用Select
Selectは性別に限定されません。任意のカテゴリの区別に使用できます:
{status, select,
active {Your account is active.}
suspended {Your account has been suspended.}
pending {Your account is pending verification.}
other {Your account status is unknown.}
}
SelectとPluralのネスト
複雑なメッセージでは、selectとpluralをネストできます:
{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}}.}
}
otherケースで動詞も変化("has" vs. "have")していることに注目してください -- これがselectが自然な翻訳テキストに不可欠な理由です。
ユースケース
通知やプロフィール更新などのソーシャル機能で、翻訳されたメッセージ内の代名詞使用と性別表現を適応させる必要がある、インクルーシブなアプリケーションを構築するUI開発者。