# gt-next: General Translation Next.js SDK: DictionaryTranslationOptions
URL: https://generaltranslation.com/zh/docs/next/api/types/dictionary-translation-options.mdx
---
title: DictionaryTranslationOptions
description: DictionaryTranslationOptions 类型的 API 参考文档
---
## 概述
`DictionaryTranslationOptions` 类型用于向字典条目传递变量,并指定其渲染方式。
它与 [`useTranslations`](/docs/next/api/dictionary/use-translations) 和 [`getTranslations`](/docs/next/api/dictionary/get-translations) 搭配使用,用于向字典条目传递变量。
**构建时翻译:**
通过 [`useTranslations`](/docs/next/api/dictionary/use-translations) 和 [`getTranslations`](/docs/next/api/dictionary/get-translations),不会翻译变量,只会翻译原始字符串。
如需翻译包含动态内容的字符串,请参阅 [`tx`](/docs/next/api/strings/tx)。
## 参考文档
### 参数
### 说明
| Prop | 说明 |
| ------------ | ------------------------------------------------- |
| `[variable]` | 变量作为选项对象的顶层键传入。键名与字典条目中的占位符对应 (例如 `{username}`) 。 |
***
## 示例
### 传递变量
要将变量传给字典条目,需要做两件事:(1) 在条目中添加变量,以及 (2) 在 [`d`](/docs/next/api/strings/use-gt) 调用中引用该变量。
首先,使用以下语法在字典条目中添加变量:`{username}`。
`username` 是变量名。
```jsx title="dictionary.ts"
// [!code word:username]
const dictionary = {
greeting: {
hello: 'Hello, {username}!',
},
};
export default dictionary;
```
接着,引用该变量:
```jsx title="Component.tsx"
// [!code word:username]
import { useTranslations } from 'gt-next';
const Component = () => {
const t = useTranslations();
return
{t('greeting.hello', { username : 'Brian123' })}
;
};
```
### 使用 ICU 消息格式
`gt-next` 支持 ICU 消息格式,因此你也可以对变量进行格式化。
```jsx title="dictionary.ts"
// [!code word:account-balance]
const dictionary = {
account: {
balance: '您的账户余额:{dollars, number, ::currency/USD}!',
},
};
export default dictionary;
```
接下来,引用该变量:
```jsx title="Component.tsx"
// [!code word:account-balance]
import { useTranslations } from 'gt-next';
const Component = () => {
const t = useTranslations();
return
{ t(
'account.balance',
{
"dollars" : 1000000,
}
) }
;
};
```
***
## 注意事项
* 变量作为选项对象中的顶层键传递,而不是嵌套在 `variables` 键下。
### 后续步骤
* 更多关于字典及常见做法的信息,请参阅 [dictionaries](/docs/next/guides/dictionaries)。
* 更多关于字典接口的信息,请参阅 [`useTranslations`](/docs/next/api/dictionary/use-translations) 或 [`getTranslations`](/docs/next/api/dictionary/get-translations)。
* 更多关于格式化选项的信息,请参阅 [`ICU message format`](https://unicode-org.github.io/icu/userguide/format_parse/messages/)。