# General Translation Platform: GTConstructorParams
URL: https://generaltranslation.com/zh/docs/platform/core/reference/types/gt-constructor-params.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: GT 构造函数可接受的配置选项。GTConstructorParams 类型的 API 参考。

`GTConstructorParams` 是传递给 General Translation [构造函数](/docs/platform/core/reference/gt-class/constructor)的对象，用于配置 [`GT`](/docs/platform/core/reference/gt-class/constructor) 实例的 API 凭据、区域设置和端点。

## 概览 [#overview]

所有属性均为可选项。未提供 `apiKey`、`devApiKey` 和 `projectId` 时，构造函数会从 `GT_API_KEY`、`GT_DEV_API_KEY` 和 `GT_PROJECT_ID` 环境变量中读取这些值。

```typescript
type GTConstructorParams = {
  apiKey?: string;
  devApiKey?: string;
  sourceLocale?: string;
  targetLocale?: string;
  locales?: string[];
  projectId?: string;
  baseUrl?: string;
  customMapping?: CustomMapping;
};
```

## 属性 [#properties]

| 属性                                 | 描述                                | 类型                                                                    | 可选 |
| ---------------------------------- | --------------------------------- | --------------------------------------------------------------------- | -- |
| [`apiKey`](#api-key)               | 项目 API Key。                       | `string`                                                              | 是  |
| [`devApiKey`](#dev-api-key)        | 备用项目 API Key，在未设置 `apiKey` 时使用。   | `string`                                                              | 是  |
| [`sourceLocale`](#source-locale)   | 默认源区域设置。                          | `string`                                                              | 是  |
| [`targetLocale`](#target-locale)   | 默认目标区域设置。                         | `string`                                                              | 是  |
| [`locales`](#locales)              | 支持的区域设置代码。                        | `string[]`                                                            | 是  |
| [`projectId`](#project-id)         | 项目标识符。                            | `string`                                                              | 是  |
| [`baseUrl`](#base-url)             | API 端点。默认为 `https://api.gtx.dev`。 | `string`                                                              | 是  |
| [`customMapping`](#custom-mapping) | 自定义区域设置映射。                        | [`CustomMapping`](/docs/platform/core/reference/types/custom-mapping) | 是  |

### `apiKey` [#api-key]

**类型** `string` · **可选**

用于翻译服务的项目 API Key。若未提供，则使用 `GT_API_KEY` 环境变量。

### `devApiKey` [#dev-api-key]

**类型** `string` · **可选**

`apiKey` 的已弃用别名，在未设置 `apiKey` 时使用。默认使用 `GT_DEV_API_KEY`；这并不会选用某种单独的、特定于环境的密钥类型。

### `sourceLocale` [#source-locale]

**类型** `string` · **可选**

翻译使用的默认源区域设置。该值会保留配置时的原始写法，并根据当前生效的自定义映射进行验证。

### `targetLocale` [#target-locale]

**类型** `string` · **可选**

翻译的默认目标区域设置。其配置中的写法会原样保留，并根据当前生效的自定义映射进行验证。

### `locales` [#locales]

**类型** `string[]` · **可选**

受支持的区域设置标识数组。原有拼写和自定义别名会被保留，并根据当前生效的自定义映射进行验证。返回的区域设置代码遵循[构造函数规则](/docs/platform/core/reference/gt-class/constructor#how-it-works)。

### `projectId` [#project-id]

**类型** `string` · **可选**

项目标识符。如未提供，则使用 `GT_PROJECT_ID` 环境变量。

### `baseUrl` [#base-url]

**类型** `string` · **可选** · **默认值** `https://api.gtx.dev`

API 端点。仅当你的部署使用其他端点时才需要覆盖它。

### `customMapping` [#custom-mapping]

**类型** [`CustomMapping`](/docs/platform/core/reference/types/custom-mapping) · **可选**

自定义区域设置代码映射及区域设置属性覆盖。 (参见 [`CustomMapping`](/docs/platform/core/reference/types/custom-mapping)) 。

## 示例 [#example]

```typescript
// 基本设置
const gt = new GT({
  apiKey: 'your-api-key',
  sourceLocale: 'en',
  targetLocale: 'es',
  locales: ['en', 'es', 'fr']
});
```

```typescript
// 使用环境变量
const gt = new GT({
  sourceLocale: 'en',
  targetLocale: 'es'
});
// 从环境变量中读取 GT_API_KEY 和 GT_PROJECT_ID
```

## Sitemap

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