# gt-node: General Translation Node.js SDK: decodeOptions
URL: https://generaltranslation.com/ja/docs/node/reference/functions/decode-options.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: General Translation のエンコードされたメッセージから options オブジェクトを復元します。decodeOptions の API リファレンス。

[`msg`](/docs/node/reference/functions/msg) がエンコードされたメッセージに埋め込んだ options オブジェクトをデコードします。エンコードされたメッセージに含まれるメタデータや補間変数を確認する際に使用します。

## 概要 [#overview]

エンコードされたメッセージを指定して `decodeOptions` を呼び出します。メッセージを解析してオプションオブジェクトを返し、メッセージにエンコードされたオプションが含まれていない場合、または解析できない場合は `null` を返します。

```ts
import { msg, decodeOptions } from 'gt-node';

const encoded = msg('Hello, {name}!', { name: 'Brian' });
console.log(decodeOptions(encoded));
// { name: 'Brian', $_source: 'Hello, {name}!', $_hash: '...' }
```

シグネチャ:

```ts
decodeOptions(encodedMsg: string): TranslationOptions | null
```

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

* **区切り文字で分割。** エンコードされたメッセージ は `interpolatedContent:encodedOptions` 形式です。`decodeOptions` は最後のコロン以降のセグメントを読み取り、base64 デコードしたうえで JSON の options を解析します。
* **`null` を返すケース。** メッセージにコロンの区切り文字がない場合、または encoded セグメントを解析できない場合は、`null` を返します。

## パラメータ [#parameters]

| パラメータ                        | 説明                          | 型        | 任意  | デフォルト |
| ---------------------------- | --------------------------- | -------- | --- | ----- |
| [`encodedMsg`](#encoded-msg) | オプションの読み取り元となるエンコードされたメッセージ。 | `string` | いいえ | —     |

### `encodedMsg` [#encoded-msg]

**Type** `string` · **Required**

デコード対象のメッセージで、通常は [`msg`](/docs/node/reference/functions/msg) が返す値です。

## 戻り値 [#returns]

**型** `TranslationOptions | null`

デコードされたオプションオブジェクトです。補間変数や、`$_source`、`$_hash` などのメタデータが含まれます。デコードするオプションがない場合は `null` を返します。

## 例 [#examples]

```ts
import { msg, decodeOptions } from 'gt-node';

const encoded = msg('You have {count} messages', { count: 3 });
const options = decodeOptions(encoded);
console.log(options?.count); // 3

console.log(decodeOptions('Plain text')); // null
```

## メモ [#notes]

* options ではなくメッセージの内容を読み取るには、[`decodeMsg`](/docs/node/reference/functions/decode-msg) を使用します。

## Sitemap

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