# gt-next: General Translation Next.js SDK: decodeVars URL: https://generaltranslation.com/ja/docs/next/api/strings/decode-vars.mdx --- title: decodeVars description: decodeVars() 文字列関数の API リファレンス --- {/* 自動生成: 直接編集しないでください。代わりに content/docs-templates/ 内のテンプレートを編集してください。 */} ## 概要 `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-next'; const encodedVar = declareVar(name); // "{_gt_, select, other {Alice}}" const decodedVar = decodeVars(encodedVar); // "Alice" ``` ### 複数の変数 `decodeVars` は複数の変数に対応しています。 ```jsx copy import { declareVar, decodeVars } from 'gt-next'; 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 MessageFormat パターンを対象としています * 元の変数値は、エンコード前の状態のまま正確に保持されます * 翻訳処理には影響せず、文字列操作のためにマーカーを削除するだけです * decodeVars は汎用的な ICU MessageFormat パーサーではないため、任意の ICU 文字列には使用しないでください ## 次のステップ * 動的コンテンツをマークする方法については [`declareVar`](/docs/next/api/strings/declare-var) を参照してください * 静的な関数呼び出しを作成する方法については [`derive`](/docs/next/api/strings/derive) を参照してください * 文字列のエンコードとデコードのパターンについては [`msg`](/docs/next/api/strings/msg) を参照してください