# gt-react: General Translation React SDK: 文字列 URL: https://generaltranslation.com/ja/docs/react/guides/strings.mdx --- title: 文字列 description: useGT を使ってプレーンテキストの文字列を国際化する方法 --- {/* 自動生成: 直接編集しないでください。content/docs-templates/ 内のテンプレートを編集してください。 */} 文字列翻訳を使うと、JSX を使わずにテキストを直接翻訳できるため、属性、オブジェクトのプロパティ、プレーンテキスト値に最適です。React コンポーネントで文字列翻訳を行うには、[`useGT`](/docs/react/api/strings/use-gt) を使用します。 ## クイックスタート ```jsx import { useGT } from 'gt-react'; 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/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 Message Format の詳細については、[Unicode のドキュメント](https://unicode-org.github.io/icu/userguide/format_parse/messages/)を参照してください。 ## 例 ### フォーム入力 ```jsx import { useGT } from 'gt-react'; function ContactForm() { const gt = useGT(); return (