Types
GTConstructorParams
用于 GT 类构造函数参数的 TypeScript 接口
概览
GTConstructorParams 定义了用于初始化 GT 类的配置项。
interface GTConstructorParams {
apiKey?: string;
devApiKey?: string;
sourceLocale?: string;
targetLocale?: string;
locales?: string[];
projectId?: string;
baseUrl?: string;
customMapping?: CustomMapping;
}所有属性均为可选。若未显式提供,构造函数会从环境变量中读取 GT_API_KEY、GT_DEV_API_KEY 和 GT_PROJECT_ID。
属性
| 属性 | 类型 | 描述 |
|---|---|---|
apiKey? | string | 生产环境 API key |
devApiKey? | string | 开发环境 API key |
sourceLocale? | string | 默认源语言(sourceLocale) |
targetLocale? | string | 默认 targetLocale |
locales? | string[] | 支持的语言代码 |
projectId? | string | 项目标识 |
baseUrl? | string | 自定义 API 端点 |
customMapping? | CustomMapping | 自定义 locale 映射 |
示例
基本设置
const gt = new GT({
apiKey: 'your-api-key',
sourceLocale: 'en',
targetLocale: 'es',
locales: ['en', 'es', 'fr']
});使用环境变量
const gt = new GT({
sourceLocale: 'en',
targetLocale: 'es'
});
// 使用环境变量中的 GT_API_KEY 和 GT_PROJECT_ID相关类型
CustomMapping- 自定义 locale 定义
本指南如何?