Translate

IAiModelText.Translate method

将提供的文档翻译成指定的目标语言。 此操作利用连接的 AI 模型进行内容翻译。

public Document Translate(Document sourceDocument, Language targetLanguage)
范围类型描述
sourceDocumentDocument需要翻译的文件。
targetLanguageLanguage文档将被翻译成的语言。

返回值

一个新的Document包含翻译文档的对象。

例子

展示如何使用 Google 模型翻译文本。

Document doc = new Document(MyDir + "Document.docx");

string apiKey = Environment.GetEnvironmentVariable("API_KEY");
// 使用 Google 生成语言模型。
IAiModelText model = (GoogleAiModel)AiModel.Create(AiModelType.Gemini15Flash).WithApiKey(apiKey);

Document translatedDoc = model.Translate(doc, Language.Arabic);
translatedDoc.Save(ArtifactsDir + "AI.AiTranslate.docx");

也可以看看