Aspose::Words::AI::AiModel::Translate method

AiModel::Translate method

Translates the provided document into the specified target language. This operation leverages the connected AI model for content translating.

virtual System::SharedPtr<Aspose::Words::Document> Aspose::Words::AI::AiModel::Translate(System::SharedPtr<Aspose::Words::Document> sourceDocument, Aspose::Words::AI::Language targetLanguage)=0
ParameterTypeDescription
sourceDocumentSystem::SharedPtr<Aspose::Words::Document>The document to be translated.
targetLanguageAspose::Words::AI::LanguageThe language into which the document will be translated.

ReturnValue

A new Document object containing the translated document.

Examples

Shows how to translate text using Google models.

auto doc = System::MakeObject<Aspose::Words::Document>(get_MyDir() + u"Document.docx");

System::String apiKey = System::Environment::GetEnvironmentVariable(u"API_KEY");
// Use Google generative language models.
System::SharedPtr<Aspose::Words::AI::AiModel> model = Aspose::Words::AI::AiModel::Create(Aspose::Words::AI::AiModelType::Gemini15Flash)->WithApiKey(apiKey);

System::SharedPtr<Aspose::Words::Document> translatedDoc = model->Translate(doc, Aspose::Words::AI::Language::Arabic);
translatedDoc->Save(get_ArtifactsDir() + u"AI.AiTranslate.docx");

See Also