# generaltranslation: General Translation Core SDK: 变量 URL: https://generaltranslation.com/zh/docs/core/types/Variable.mdx --- title: 变量 description: 翻译内容中所用变量的类型定义 --- ## 概述 `Variable` 用于表示翻译中动态内容的占位符。 ```typescript type Variable = { k: string; i?: number; v?: VariableType; }; ``` ## 属性 | 属性 | 类型 | 描述 | | ---- | -------------- | ----- | | `k` | `string` | 变量键名 | | `i?` | `number` | 内部标识符 | | `v?` | `VariableType` | 格式化类型 | ### VariableType ```typescript type VariableType = 'v' | 'n' | 'd' | 'c'; ``` | 值 | 描述 | | ----- | ----- | | `'v'` | 纯文本替换 | | `'n'` | 数字格式化 | | `'d'` | 日期格式化 | | `'c'` | 货币格式化 | ## 示例 ### 基本用法 ```typescript copy import { Variable } from 'generaltranslation'; // 文本变量 const nameVariable: Variable = { k: 'userName' }; // 数字变量 const countVariable: Variable = { k: 'itemCount', v: 'n' }; // 货币变量 const priceVariable: Variable = { k: 'price', v: 'c' }; ``` ### 在 JSX 内容中 ```typescript copy const welcomeContent = [ 'Welcome back, ', { k: 'userName' } as Variable, '! You have ', { k: 'messageCount', v: 'n' } as Variable, ' messages.' ]; ``` ## 相关类型 * [`VariableType`](/docs/core/types/variable-type) - 格式化类型说明