# General Translation Platform: getProjectData
URL: https://generaltranslation.com/zh/docs/platform/core/reference/gt-class-methods/translation/get-project-data.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 读取项目级元数据和翻译配置。getProjectData 的 API 参考。

获取 General Translation 中翻译项目的信息，包括其名称、组织、默认区域设置以及当前配置的目标区域设置。可用于检查或验证项目配置。

## 概览 [#overview]

使用项目 ID 调用 `getProjectData`。该方法会返回只读的项目元数据和区域设置配置。

```typescript
const gt = new GT({ projectId: 'your-project-id', apiKey: 'your-api-key' });

const projectData = await gt.getProjectData('project-123');
console.log(`Project: ${projectData.name}`);
console.log(`Default locale: ${projectData.defaultLocale}`);
console.log(`Target locales: ${projectData.currentLocales.join(', ')}`);
```

签名：

```typescript
getProjectData(
  projectId: string,
  options?: { timeout?: number }
): Promise<ProjectData>
```

*注意：`getProjectData` 要求 GT 实例上提供 `apiKey` (或 `devApiKey`) 和 `projectId`，并且该 API 密钥必须有权访问该项目。*

## 工作原理 [#how-it-works]

* **只读。** 此方法仅提供对项目信息的只读访问；如需修改项目“设置”，请使用仪表板。
* **区域设置配置。** 响应同时包含源 (`defaultLocale`) 和目标 (`currentLocales`) 区域设置配置。
* **验证。** 可在启动翻译工作流之前用它来验证项目配置。

## 参数 [#parameters]

| 参数                         | 描述           | 类型                     | 可选 | 默认值 |
| -------------------------- | ------------ | ---------------------- | -- | --- |
| [`projectId`](#project-id) | 要获取的项目唯一标识符。 | `string`               | 否  | —   |
| [`options`](#options)      | 请求配置。        | `{ timeout?: number }` | 是  | —   |

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

**类型** `string` · **必填**

要获取的项目的唯一标识符。该项目必须能通过所提供的 API 密钥进行访问。

### `options` [#options]

**类型** `{ timeout?: number }` · **可选**

| 字段        | 描述                | 类型       | 可选 |
| --------- | ----------------- | -------- | -- |
| `timeout` | 请求超时时间 (以毫秒为单位) 。 | `number` | 是  |

## 返回 [#returns]

**类型** `Promise<ProjectData>`

会解析为一个描述该项目的 `ProjectData` 对象：

```typescript
type ProjectData = {
  id: string;
  name: string;
  orgId: string;
  defaultLocale: string;
  currentLocales: string[];
};
```

| 属性               | 描述            | 类型         |
| ---------------- | ------------- | ---------- |
| `id`             | 唯一的项目标识符。     | `string`   |
| `name`           | 易于识别的项目名称。    | `string`   |
| `orgId`          | 拥有该项目的组织标识符。  | `string`   |
| `defaultLocale`  | 该项目的默认源区域设置。  | `string`   |
| `currentLocales` | 当前已配置的目标区域设置。 | `string[]` |

## 示例 [#examples]

```typescript title="index.ts"
import { GT } from 'generaltranslation';

const gt = new GT({
  projectId: 'your-project-id',
  apiKey: 'your-api-key',
});

async function getProjectInfo(projectId: string) {
  try {
    const project = await gt.getProjectData(projectId);

    console.log('=== Project Information ===');
    console.log(`ID: ${project.id}`);
    console.log(`Name: ${project.name}`);
    console.log(`Organization: ${project.orgId}`);
    console.log(`Default Locale: ${project.defaultLocale}`);
    console.log(`Target Locales: ${project.currentLocales.join(', ')}`);

    return project;
  } catch (error) {
    console.error(`Failed to retrieve project ${projectId}:`, error);
    throw error;
  }
}

const projectInfo = await getProjectInfo('my-project-123');
```

## 注意事项 [#notes]

* 该方法仅提供对项目信息的只读访问；如需修改项目“设置”，请使用仪表板。
* 此方法需要有效的项目 ID；并且该项目必须可通过提供的 API 密钥访问。
* 项目数据同时包含源区域设置和目标区域设置的配置。
* `currentLocales` array 表示该项目中已配置的所有目标区域设置。
* 在启动翻译工作流之前，可使用此方法验证项目配置。

## Sitemap

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