# gt-react: General Translation React SDK: decodeVars URL: https://generaltranslation.com/ja/docs/react/api/strings/decode-vars.mdx --- title: decodeVars description: decodeVars() 文字列関数のAPIリファレンス --- {/* 自動生成: 直接編集せず、代わりに content/docs-templates/ の template を編集してください。 */} ## 概要 `declareVar` はソーステキストに ICU 互換のマーカーを追加するため、既存の文字列処理ロジックで問題を引き起こす可能性があります。 `decodeVars` 関数は、`declareVar` マーカーを含む文字列から元の値を抽出します。 ```jsx function getGreeting({ name }) { const greeting = "Hello, " + declareVar(name); // "Hello, {_gt_, select, other {Brian}}" const decodedGreeting = decodeVars(greeting); // "Hello, Brian" <- `declareVar` を使用しなかった場合と同じ文字列 return decodedGreeting; } ``` `declareVar` が影響するのはエンコードされた文字列だけなので、使用できるのはソース文字列に限られ、翻訳済みの文字列には影響しません。 **文字列処理:** 既存の文字列操作ロジックで `declareVar` マーカーを含む文字列を処理する必要がある場合は、`decodeVars` を使用してください。 ## リファレンス ### パラメータ | 名前 | 型 | 説明 | | ----------- | -------- | ---------------------------------------- | | `icuString` | `string` | `declareVar` の呼び出しで生成される ICU マーカーを含む文字列。 | ### 戻り値 ICUマーカーを削除し、元の変数値を含む文字列。 *** ## 例 ### 基本的な使い方 変数マーカー付きの文字列から元の値を抽出します。 ```jsx copy import { declareVar, decodeVars } from 'gt-react'; const encodedVar = declareVar(name); // "{_gt_, select, other {Alice}}" const decodedVar = decodeVars(encodedVar); // "Alice" ``` ### 複数の変数 `decodeVars` は複数の変数に対応しています。 ```jsx copy import { declareVar, decodeVars } from 'gt-react'; const name1 = "Alice"; const name2 = "Bob"; const encodedVar = "Hello, " + declareVar(name1) + "! My name is " + declareVar(name2); // "Hello, {_gt_, select, other {Alice}}! My name is {_gt_, select, other {Bob}}" const decodedVar = decodeVars(encodedVar); // "Hello, Alice! My name is Bob" ``` *** ## 注意事項 * `declareVar` マーカーを含む文字列を処理する必要がある場合にのみ、`decodeVars` を使用してください * この関数は、`declareVar` によって生成された ICU メッセージ形式 パターンを対象としています * 元の変数値は、エンコード前とまったく同じ形で保持されます * 翻訳処理には影響せず、文字列操作のためにマーカーを削除するだけです * `decodeVars` は汎用的な ICU メッセージ形式 パーサーではないため、任意の ICU 文字列に使用しないでください ## 次のステップ * 動的なコンテンツをマークするには [`declareVar`](/docs/react/api/strings/declare-var) を参照してください * 静的な関数呼び出しを生成するには [`derive`](/docs/react/api/strings/derive) を参照してください * 文字列のエンコードとデコードのパターンについては [`msg`](/docs/react/api/strings/msg) を参照してください