# General Translation React SDKs (gt-react, gt-next, gt-react-native): 複数形と分岐の扱い
URL: https://generaltranslation.com/ja/docs/react/guides/handling-plurals-and-branches.mdx
---
title: 複数形と分岐の扱い
description: と を使用して、React の複数形処理と条件付き翻訳済みコンテンツを扱う方法。
related:
links:
- /docs/react/guides/formatting-variables
- /docs/react/guides/translating-jsx
- /docs/react/guides/translating-strings
- /docs/react/guides/translating-with-dictionaries
---
ロケールごとに使用する複数形は異なります。英語では通常 `one` と `other` が使用されますが、追加の形式が必要な言語もあります。
数に応じた表現には [``](/docs/react/reference/components/plural) を使用し、それ以外の条件付きコンテンツには [``](/docs/react/reference/components/branch) を使用します。
## 複数形または分岐を選択する [#choose]
* メッセージ数や検索結果のように、数値によって文言が決まる場合は [``](/docs/react/reference/components/plural) を使用します。
* status、プラン、ブール値など、値によってコンテンツが決まる場合は [``](/docs/react/reference/components/branch) を使用します。
* すべてのバリエーションを翻訳できるよう、いずれのコンポーネントも [``](/docs/react/reference/components/t) 内に配置します。
* 各バリエーション内の動的な値は、[``](/docs/react/reference/components/num) や [``](/docs/react/reference/components/var) などの[変数コンポーネント](/docs/react/guides/formatting-variables)でラップします。
どちらのコンポーネントも、React、Next.js、TanStack Start、React Native で同様に動作します。異なるのはインポートするパッケージだけです。
## `` で複数形を切り替える [#plural]
`count === 1` を確認したり `s` を追加したりして複数形を作成しないでください。これは英語の文法しか表現できません。数を [`n`](/docs/react/reference/components/plural#n) として渡し、ソース言語で使う形式を指定します。[``](/docs/react/reference/components/plural) は、アクティブなロケールの[Unicode CLDR plural rules](https://cldr.unicode.org/index/cldr-spec/plural-rules)に基づいて正しい形式を選択します。
```tsx
import { T, Plural, Num } from 'gt-react';
You have {count} message.>}
other={<>You have {count} messages.>}
/>
;
```
```tsx
import { T, Plural, Num } from 'gt-next';
You have {count} message.>}
other={<>You have {count} messages.>}
/>
;
```
```tsx
import { T, Plural, Num } from 'gt-tanstack-start';
You have {count} message.>}
other={<>You have {count} messages.>}
/>
;
```
```tsx
import { T, Plural, Num } from 'gt-react-native';
You have {count} message.}
other={You have {count} messages.}
/>
;
```
ソース言語で使う[`複数形カテゴリ`](/docs/react/reference/components/plural#form)を指定してください。英語では通常 `one` と `other` です。`zero`、`two`、`few`、`many` など、各ターゲット言語で必要なカテゴリは翻訳者が補います。
完全に一致するカテゴリが利用できない場合、[``](/docs/react/reference/components/plural) は `plural` 分岐を使用し、次に `other` を使用します。どちらの汎用分岐も存在しない場合にのみ、[`children`](/docs/react/reference/components/plural#children) がレンダリングされます。
```tsx
One result>}>
{count} results
;
```
## 値に応じて `` で分岐する [#branch]
コンテンツが数以外の値に依存する場合は、[``](/docs/react/reference/components/branch) を使用します。値は [`branch`](/docs/react/reference/components/branch#branch) として渡し、[想定される各値に対応する prop](/docs/react/reference/components/branch#value) を追加し、フォールバックとして [`children`](/docs/react/reference/components/branch#children) を使用します。
```tsx
Upgrade to unlock more.
}
pro={Thanks for going Pro!
}
>
Welcome.
;
```
各分岐は独立して翻訳されるため、翻訳者はインラインの JavaScript 条件分岐に縛られず、文言全体を調整できます。
### `` 内の条件分岐を置き換える
インラインの三項演算子を使用すると、[``](/docs/react/reference/components/t) の children が動的になり、確実に抽出できなくなります。同じ条件は、[``](/docs/react/reference/components/branch) で表現してください。
```tsx
// ❌ インラインの条件分岐
{isActive ? 'Active' : 'Inactive'};
// ✅ 翻訳可能な branch
Inactive
;
```
*メモ: [``](/docs/react/reference/components/branch) では、予約されていないpropsが分岐の値を表すため、`data-*`属性は無視されます。テストIDなどのデータ属性はラッパー要素に指定してください。[`no-data-attrs-on-branch`](/docs/react/reference/lint-rules#no-data-attrs) lintルールはこの誤りを検出します。*
## Next steps
- /docs/react/guides/formatting-variables
- /docs/react/guides/translating-jsx
- /docs/react/guides/translating-strings
- /docs/react/guides/translating-with-dictionaries