# generaltranslation: General Translation Core SDK: TranslationResult URL: https://generaltranslation.com/ja/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(`Translation: ${result.translation}`); } else { console.error(`Translation failed: ${result.error}`); } ``` ### 判別子を使う ```typescript copy if (result.success) { // 成功時の処理 — result.translation が利用可能 } else { // エラー時の処理 — result.error と result.code が利用可能 } ``` ## 関連型 * [`TranslateManyResult`](/docs/core/types/translate-many-result) - バッチ翻訳の結果