',
optional: true,
default: 'undefined',
},
}}
/>
### 説明
| Prop | 説明 |
| ----------- | ------------------------------------------------------------------------------------------- |
| `variables` | 各キーで、各値を文字列内のどこに対応付けるかを指定するオブジェクトです。 |
| `$context` | 必要に応じて、コンテンツのコンテキスト (翻訳に使用) を渡すために、`variables` オブジェクトに `$context` を変数として含めます。 |
| `$id` | 必要に応じて、翻訳エディタで使用する識別子を渡すために、`variables` オブジェクトに `$id` を変数として含めます。 |
| `$maxChars` | 必要に応じて、翻訳の文字数を制限するための変数として `$maxChars` を含めます。ライブラリは `formatCutoff()` ロジックを使ってこの上限を厳密に適用します。 |
***
## 例
### コンテキスト
文字列にコンテキストを追加するには、`$context` prop を使います。
```jsx title="Component.tsx"
// [!code word:$context]
import { useGT } from 'gt-react-native';
const Component = () => {
const gt = useGT();
return {gt('Hello, world!', { $context: '丁寧な挨拶' })}
;
};
```
### 変数を渡す
文字列に変数を追加するには、`{variable-name}` 構文を使用します。これは、変数名を中かっこで囲む形式です。
```jsx title="Component.tsx"
// [!code word:username]
import { useGT } from 'gt-react-native';
const Component = () => {
const gt = useGT();
return {gt('Hello, {username}! How is your day?', { username: 'Brian123' })}
;
};
```
### ICU message format を使う
`gt-react-native` は ICU message format をサポートしているため、変数の書式も設定できます。
```jsx title="Component.tsx"
// [!code word:account-balance]
import { useGT } from 'gt-react-native';
const Component = () => {
const gt = useGT();
return
{ gt(
'Your account balance: {dollars, number, ::currency/USD}!',
{
"dollars" : 1000000,
}
) }
;
};
```
ICU message format の詳細については、[ICU message format documentation](https://unicode-org.github.io/icu/userguide/format_parse/messages/)を参照してください。
### 字符制限
翻訳の長さを制限するには `$maxChars` を使用します:
```jsx title="Component.tsx"
// [!code word:$maxChars]
import { useGT } from 'gt-react-native';
const Component = () => {
const gt = useGT();
return {gt('Welcome to our application', { $maxChars: 15 })}
;
// Output: "Bienvenue à no\u202F…"
};
```
***
## 注記
* `InlineTranslationOptions` は、インライン文字列の翻訳をする際に使用します。
* `variables` オブジェクトは、テキストに値を渡します。
* `variablesOptions` オブジェクトは、変数の挙動を定義します。
## 次のステップ
* インライン文字列の翻訳の詳細については、[`useGT`](/docs/react-native/api/strings/use-gt)を参照してください。
* 書式設定オプションの詳細については、[`ICU message format`](https://unicode-org.github.io/icu/userguide/format_parse/messages/)を参照してください。