# generaltranslation: General Translation Core SDK: TranslationResult URL: https://generaltranslation.com/zh/docs/core/types/translation-result.mdx --- title: TranslationResult description: "`translate()` 方法返回的翻译结果类型定义" --- ## 概述 `TranslationResult` 表示翻译操作的结果。 ```typescript type TranslationResult = RequestSuccess | TranslationError; ``` ## 联合类型 ### RequestSuccess ```typescript type RequestSuccess = TypedResult & { success: true; locale: string; }; ``` ### TranslationError ```typescript type TranslationError = { success: false; error: string; code: number; }; ``` ## 示例 ### 基本错误处理 ```typescript copy import { GT, TranslationResult } from 'generaltranslation'; const gt = new GT({ apiKey: 'your-api-key' }); const result: TranslationResult = await gt.translate('Hello'); if (result.success) { console.log(`翻译结果:${result.translation}`); } else { console.error(`翻译失败:${result.error}`); } ``` ### 使用判别属性 ```typescript copy if (result.success) { // 处理成功情况 — result.translation 可用 } else { // 处理错误情况 — result.error 和 result.code 可用 } ``` ## 相关类型 * [`TranslateManyResult`](/docs/core/types/translate-many-result) - 批量翻译的结果