# generaltranslation: General Translation Core SDK: getProjectData URL: https://generaltranslation.com/zh/docs/core/class/methods/translation/get-project-data.mdx --- title: getProjectData description: 用于获取项目信息和配置的 getProjectData 方法 API 参考 --- ## 概述 `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(', ')}`); ``` ## 参考 ### 参数 | 名称 | 类型 | 说明 | | ----------- | ---------------------- | ----------- | | `projectId` | `string` | 要获取的项目唯一标识符 | | `options?` | `{ timeout?: number }` | 请求的可选配置 | #### 选项 | 名称 | 类型 | 说明 | | ---------- | -------- | ---------- | | `timeout?` | `number` | 请求超时,单位为毫秒 | ### 返回值 `Promise` - 包含项目相关信息和设置。 ```typescript type ProjectData = { id: string; name: string; orgId: string; defaultLocale: string; currentLocales: string[]; } ``` | 属性 | 类型 | 说明 | | ---------------- | ---------- | -------------- | | `id` | `string` | 唯一的项目标识符 | | `name` | `string` | 便于识别的项目名称 | | `orgId` | `string` | 拥有该项目的组织标识符 | | `defaultLocale` | `string` | 项目的默认源区域设置 | | `currentLocales` | `string[]` | 当前已配置的目标区域设置数组 | *** ## 示例 ### 基本用法 ```typescript title="index.ts" copy 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'); ``` *** ## 说明 * 此方法仅提供对项目信息的只读访问;如需修改项目设置,请使用仪表板 * 此方法需要有效的项目 ID;并且必须能使用提供的 API 密钥访问该项目 * 项目数据同时包含源区域设置和目标区域设置的配置 * `currentLocales` 数组表示项目中配置的所有目标区域设置 * 在启动翻译工作流之前,可使用此方法验证项目配置 ## 后续步骤 * 请参阅 [`setupProject`](/docs/core/class/methods/translation/setup-project) 以完成项目初始化设置 * 请参阅 [`enqueueFiles`](/docs/core/class/methods/translation/enqueue-files) 以启动翻译任务 * 请参阅 [`querySourceFile`](/docs/core/class/methods/translation/query-source-file) 以获取特定文件的信息