Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Document translation is a frequently needed option in the age of high digitalization. Aspose.Words supports document translation using Google generative language models, which allows developers to translate texts content into more than 300 languages.
Use the Translate method to translate your documents into any language represented in the Language enumeration. Note that if the source document contains several languages, the Google AI‑based model will be able to translate all supported languages. If the model cannot recognize the language in some text fragments, then you will be returned a document with these untranslated fragments and with the rest of the text translated.
The following code example shows how to use the Gemini 1.5 Flash model in Aspose.Words to translate a document into Arabic:
void AiTranslate()
{
auto doc = MakeObject<Document>(MyDir + u"Document.docx");
SharedPtr<IAiModelText> model = System::ExplicitCast<GoogleAiModel>(MakeObject<AiModel>()->Create(AiModelType::Gpt4OMini)->WithApiKey(u"API_KEY"));
auto translatedDoc = model->Translate(doc, Language::Arabic);
translatedDoc->Save(ArtifactsDir + u"AI.AiTranslate.docx");
}
Q: Which languages can I translate a document into with Aspose.Words AI?
A: The Translate method supports any language defined in the Aspose.Words.AI::Language enumeration, which currently includes more than 300 languages provided by Google generative models.
Q: Do I need a Google API key to use the Translate method?
A: Yes. When creating a GoogleAiModel you must supply a valid Google Cloud API key via WithApiKey. The key authorizes calls to the underlying Google AI service.
Q: How does the Translate method handle documents that contain multiple source languages?
A: The AI model automatically detects the language of each text fragment. It translates each fragment to the target language independently, so mixed‑language source documents are fully supported.
Q: What happens if the AI model cannot recognize the language of a text fragment?
A: Unrecognizable fragments are left unchanged in the output document, while all other recognizable text is translated. This allows you to identify and handle those fragments manually if needed.
Q: Can I use a different AI model (e.g., Gemini 1.5 Pro) for translation?
A: Yes. Replace AiModelType::Gpt4OMini with the desired model type, such as AiModelType::Gemini15Pro, when creating the AiModel. The rest of the code remains the same.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.