# react-native: 文字列 URL: https://generaltranslation.com/ja/docs/react-native/guides/strings.mdx --- title: 文字列 description: useGT を使ってプレーンテキストの文字列を国際化する方法 --- {/* 自動生成: 直接編集せず、content/docs-templates/ のテンプレートを編集してください。 */} 文字列翻訳を使うと、JSX を使わずにテキストを直接翻訳できるため、属性、オブジェクトのプロパティ、プレーンテキストの値に最適です。React Native コンポーネントで文字列を翻訳するには、[`useGT`](/docs/react-native/api/strings/use-gt) を使用します。 ## クイックスタート ```jsx import { useGT } from 'gt-react-native'; function MyComponent() { const gt = useGT(); return ( ); } ``` ## 文字列翻訳を使うタイミング JSX ではなくプレーンテキストが必要な場合は、文字列翻訳が適しています。 ### HTML属性 ```jsx const gt = useGT(); ``` ### オブジェクトのプロパティ ```jsx const gt = useGT(); const user = { name: 'John', role: 'admin', bio: gt('Experienced software developer with 5 years in React'), status: gt('Currently available for projects') }; ``` ### 設定と定数 ```jsx const gt = useGT(); const navigationItems = [ { label: gt('Home'), href: '/' }, { label: gt('Products'), href: '/products' }, { label: gt('Contact'), href: '/contact' } ]; ``` ### 代わりにTを使う場合 JSXコンテンツには、[``コンポーネント](/docs/react-native/api/components/t)を使用します。 ```jsx // ✅ JSXコンテンツにはを使用する

Welcome to our store!

// ✅ プレーンテキストには文字列翻訳を使用する ``` ## 変数を使う ### 基本的な変数 プレースホルダーを動的な値で置き換えます。 ```jsx const gt = useGT(); const itemCount = 5; // プレースホルダー付きの文字列 const message = gt('You have {count} items in your cart', { count: itemCount }); // 結果: "You have 5 items in your cart" ``` ### 複数の変数 ```jsx const gt = useGT(); const order = { id: 'ORD-123', total: 99.99, date: '2024-01-15' }; const confirmation = gt( 'Order {orderId} for ${total} was placed on {date}', { orderId: order.id, total: order.total, date: order.date } ); ``` ### ICUメッセージ形式 高度な書式設定を行うには、ICU構文を使用します。 ```jsx const gt = useGT(); translate('There are {count, plural, =0 {no items} =1 {one item} other {{count} items}} in the cart', { count: 10 }); ``` ICUメッセージ形式 の詳細については、[Unicode のドキュメント](https://unicode-org.github.io/icu/userguide/format_parse/messages/)を参照してください。 ## 例 ### フォームの入力欄 ```jsx import { useGT } from 'gt-react-native'; function ContactForm() { const gt = useGT(); return (