# gt-node: General Translation Node.js SDK: decodeVars
URL: https://generaltranslation.com/ja/docs/node/reference/functions/decode-vars.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: General Translation の declareVar 変数を文字列へ復元します。decodeVars の API リファレンス。

[`declareVar`](/docs/node/reference/functions/declare-var) によって ICU 文字列にエンコードされた `_gt_` 変数を展開し、エンコードされた各 `select` 式をその値に置き換えます。

## 概要 [#overview]

[`declareVar`](/docs/node/reference/functions/declare-var) の出力を含む ICU 文字列を `decodeVars` に渡します。すると、各エンコードされた変数がそれぞれの `other` 値に置き換えられた文字列が返されます。`_gt_` 変数を含まない文字列は、そのまま返されます。

```ts
import { decodeVars, declareVar } from 'gt-node';

const encoded = 'Hi ' + declareVar('Brian') + ', my name is {name}';
const decoded = decodeVars(encoded);
console.log(decoded); // 'Hi Brian, my name is {name}'
```

シグネチャ:

```ts
decodeVars(icuString: string): string
```

## 仕組み [#how-it-works]

* **対象を限定した補間。** 補間されるのは [`declareVar`](/docs/node/reference/functions/declare-var) で生成された `_gt_` 変数のみで、その他の ICU プレースホルダー (`{name}` など) はそのまま保持されます。
* **パススルー。** 文字列に `_gt_` 識別子が含まれていない場合は、変更せずそのまま返されます。

## パラメータ [#parameters]

| パラメータ                      | 説明             | 型        | 任意  | デフォルト |
| -------------------------- | -------------- | -------- | --- | ----- |
| [`icuString`](#icu-string) | 補間対象の ICU 文字列。 | `string` | いいえ | —     |

### `icuString` [#icu-string]

**型** `string` · **必須**

[`declareVar`](/docs/node/reference/functions/declare-var) でエンコードされた `_gt_` 変数を含む可能性がある ICU 文字列。

## 戻り値 [#returns]

**型** `string`

エンコードされた `_gt_` 変数があればその値に置き換えた文字列を、なければ入力値をそのまま返します。

## 例 [#examples]

```ts
import { decodeVars, declareVar } from 'gt-node';

const encoded = 'Hi ' + declareVar('Brian') + ', my name is {name}';
console.log(decodeVars(encoded)); // 'Hi Brian, my name is {name}'
```

## メモ [#notes]

* `decodeVars` は [`declareVar`](/docs/node/reference/functions/declare-var) を補完する関数で、影響するのは `_gt_` 変数のみです。

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
