@@ -55,7 +55,7 @@ actor NLTranslator {
5555
5656 // 检查是否支持该语言对
5757 guard await isLanguagePairSupported ( source: sourceLang, target: targetLang) else {
58- throw TranslationError . unsupportedLanguagePair ( source: normalizedSource, target: normalizedTarget)
58+ throw NLTranslationError . unsupportedLanguagePair ( source: normalizedSource, target: normalizedTarget)
5959 }
6060
6161 // 使用 macOS 的翻译 API
@@ -104,17 +104,16 @@ actor NLTranslator {
104104
105105 print ( " ✅ 翻译成功: \( translatedText. prefix ( 50 ) ) ... " )
106106 return translatedText
107- } catch let error as TranslationError {
108- if error. cause == . notInstalled {
107+ } catch {
108+ // 检查是否是语言包未安装错误
109+ let errorString = String ( describing: error)
110+ if errorString. contains ( " notInstalled " ) {
109111 print ( " ⚠️ 语言包未安装: \( source. rawValue) -> \( target. rawValue) " )
110112 print ( " 请在系统设置中下载翻译语言包 " )
111- throw TranslationError . languagePackNotInstalled ( source: source. rawValue, target: target. rawValue)
113+ throw NLTranslationError . languagePackNotInstalled ( source: source. rawValue, target: target. rawValue)
112114 }
113115 print ( " ❌ Translation 框架失败: \( error) " )
114- throw TranslationError . translationNotAvailable
115- } catch {
116- print ( " ❌ Translation 框架失败: \( error) " )
117- throw TranslationError . translationNotAvailable
116+ throw NLTranslationError . translationNotAvailable
118117 }
119118 }
120119
@@ -182,7 +181,7 @@ actor NLTranslator {
182181 try ? FileManager . default. removeItem ( at: inputFile)
183182 try ? FileManager . default. removeItem ( at: outputFile)
184183
185- throw TranslationError . translationNotAvailable
184+ throw NLTranslationError . translationNotAvailable
186185 }
187186
188187
@@ -287,7 +286,7 @@ actor NLTranslator {
287286 }
288287}
289288
290- enum TranslationError : LocalizedError {
289+ enum NLTranslationError : LocalizedError {
291290 case unsupportedLanguage
292291 case unsupportedLanguagePair( source: String , target: String )
293292 case translationNotAvailable
0 commit comments