{"id":22539741,"url":"https://github.com/gasparl/openai_translation","last_synced_at":"2025-08-16T05:34:56.213Z","repository":{"id":266608326,"uuid":"898832841","full_name":"gasparl/openai_translation","owner":"gasparl","description":"Python script for translating .docx documents using the OpenAI API. It processes text in chunks, maintains context, supports sample translations for style, and saves results in .docx format.","archived":false,"fork":false,"pushed_at":"2025-03-02T07:23:47.000Z","size":33,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T18:57:59.839Z","etag":null,"topics":["book-translation","books","chatgpt-api","docx","openai","openai-api","translation","translation-api"],"latest_commit_sha":null,"homepage":"https://gasparl.github.io/openai_translation/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gasparl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-05T05:52:57.000Z","updated_at":"2025-04-14T13:34:56.000Z","dependencies_parsed_at":"2025-03-02T08:20:36.110Z","dependency_job_id":"69a2abfa-b107-4400-a48a-bb7d0ae00e5d","html_url":"https://github.com/gasparl/openai_translation","commit_stats":null,"previous_names":["gasparl/openai_translation"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/gasparl/openai_translation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gasparl%2Fopenai_translation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gasparl%2Fopenai_translation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gasparl%2Fopenai_translation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gasparl%2Fopenai_translation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gasparl","download_url":"https://codeload.github.com/gasparl/openai_translation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gasparl%2Fopenai_translation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270671165,"owners_count":24625716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-16T02:00:11.002Z","response_time":91,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["book-translation","books","chatgpt-api","docx","openai","openai-api","translation","translation-api"],"created_at":"2024-12-07T12:08:18.534Z","updated_at":"2025-08-16T05:34:56.184Z","avatar_url":"https://github.com/gasparl.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docx Translator with OpenAI\n\nThis repository provides a Python script for translating `.docx` files using OpenAI's GPT(-4) API.\n\n---\n\n## Features\n\n- Supports translation between any pair of languages (configurable in the script).\n- Handles large texts by splitting them into manageable chunks that fit OpenAI's token limits.\n- Maintains contextual continuity by incorporating previous translations and source text into the translation process.\n- Allows the use of a sample translation file to guide translation tone and style.\n- The specific instructions can be modified. (The current instructions focuse on formal equivalence, aiming to preserve the original meaning, style, and structure of the text.)\n- Reads input from `.docx` files and writes translated output to `.docx` files while preserving paragraph structure.\n- Includes error handling and retry mechanisms for API calls.\n\n---\n\n## Requirements\n\n1. Python 3.7 or higher.\n2. Required libraries:\n   - `openai`\n   - `python-docx`\n   - `tiktoken`\n3. A valid OpenAI API key.\n\nTo install the required libraries, run:\n\n```bash\npip install openai python-docx tiktoken\n## Setup\n\n### Configuration File\n\nCreate a `config.json` file in the same directory as the script and add your OpenAI API key:\n\n```json\n{\n    \"OPENAI_API_KEY\": \"your-api-key-here\"\n}\n```\n\n### Input\n\n- Prepare the `.docx` file you want to translate.\n- Optionally, create a `.docx` file with sample translations to guide the translation style.\n\n---\n\n## Usage\n\n1. Open the script and modify the `main()` function call:\n\n   ```python\n   main('input.docx', 'output.docx', sample_translation_file='sample_translation.docx')\n   ```\n\n   - Replace `input.docx` with the path to your input file.\n   - Replace `output.docx` with the desired output file path.\n   - Optionally, specify a sample translation file.\n\n2. Run the script; e.g. in bash:\n\n   ```bash\n   python openai_translator.py\n   ```\n\n3. The translated document will be saved as the specified output file.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgasparl%2Fopenai_translation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgasparl%2Fopenai_translation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgasparl%2Fopenai_translation/lists"}