Google Gemini AI モデルと Aspose.Words for Python via .NET を使用して、DOCX ドキュメントの翻訳を自動化します。DOCX ファイルを 300 以上の言語に翻訳し、元のレイアウト、書式設定、ドキュメント構造を保持します。
AI エンジンはソース言語を自動的に検出します — 混在言語のドキュメントでも対応可能です。以下の例は、Python で DOCX ドキュメントを翻訳する方法を示しています。
pip install aspose-words
コピー
doc = aw.Document("Document.docx")
api_key = os.getenv("API_KEY")
# Google の生成言語モデルを使用します。
model = aw.ai.AiModel.create(aw.ai.AiModelType.GEMINI_FLASH_LATEST).with_api_key(api_key)
translated_doc = model.translate(doc, aw.ai.Language.ARABIC)
translated_doc.save("Output.docx")
doc = aw.Document("Document.docx")
# Pass an empty string if the self-hosted model does not require an API key.
model = CustomAiModel("my-model-24b", "https://your-server.com/v1").with_api_key("")
translated_doc = model.translate(doc, aw.ai.Language.ARABIC)
translated_doc.save("Output.docx")
class CustomAiModel(aw.ai.OpenAiModel):
def __init__(self, name, url):
super().__init__(name)
self._url = url
@property
def url(self):
return self._url
Python パッケージはPyPiリポジトリでホストしています。 "Aspose.Words for Python via .NET" 開発者環境にインストールする方法のステップバイステップの説明に従ってください。
このパッケージは Python ≥3.5 および <3.12 と互換性があります。 Linux 用のソフトウェアを開発する場合は、 製品ドキュメントの gcc および libpython の追加要件を参照してください。