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_KEYGT_DEV_API_KEYGT_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

相关类型

本指南如何?