https://github.com/coolcat467/subtitle-translate
Translate subtitle files with google translate.
https://github.com/coolcat467/subtitle-translate
coolcat467 subtitle subtitle-translation subtitle-translator subtitles subtitles-parsing utility
Last synced: 12 months ago
JSON representation
Translate subtitle files with google translate.
- Host: GitHub
- URL: https://github.com/coolcat467/subtitle-translate
- Owner: CoolCat467
- License: gpl-3.0
- Created: 2024-11-03T07:56:08.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-01T01:52:48.000Z (about 1 year ago)
- Last Synced: 2025-06-18T18:04:48.099Z (12 months ago)
- Topics: coolcat467, subtitle, subtitle-translation, subtitle-translator, subtitles, subtitles-parsing, utility
- Language: Python
- Homepage:
- Size: 409 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Subtitle-Translate
Script for translating Subtitle (.srt and .vtt) files with google translate.
[](https://github.com/CoolCat467/Subtitle-Translate/actions/workflows/ci.yml)
[](https://results.pre-commit.ci/latest/github/CoolCat467/Subtitle-Translate/main)
[](https://github.com/pre-commit/pre-commit)
[](https://github.com/psf/black)
[](https://github.com/astral-sh/ruff)
## Installation
```console
pip install git+https://github.com/CoolCat467/Localization-Translation-Utility.git
```
## Usage
If you don't already have a separate subtitle file, you can
extract subtitles from your video file with something like this:
```console
ffmpeg -i Movie.mkv -map 0:s:0 subtitles.srt
```
You might need to change the last 0 if there is more than one subtitle
track in your file.
This script also supports `.vtt` files as of v0.1.0.
Please note that this will absolutely not work at all if your video file
does have a baked-in subtitle track!
### Example
Say `subtitles.srt` is in French, but you want it to be English. In that case, run
```bash
subtitle_translate --source-lang fr subtitles.srt
```
which will create `subtitles.en.srt` in the current working directory because we didn't specify `--dest-file` and it used the default
output filename formatting.
Another example, say `subtitles.ko.vtt` is in Korean but you want it in English.
```bash
subtitle_translate subtitles.ko.vtt
```
which will create `subtitles.en.vtt` in the current working directory, because in `vtt` processing mode it's smarter and
reads the `Language: ko` tag from the file header and knows it's in Korean. Reminder, if `--source-lang` not specified and can't
find language from file header if in `vtt` mode, it will default to `auto` and have google translate guess what the source
language is, which while it works might not be as accurate.
### Command Help Information
```console
> subtitle_translate
usage: subtitle_translate [-h] [--version] [--source-lang SOURCE_LANG] [--source-type SOURCE_TYPE] [--dest-lang DEST_LANG]
[--dest-file DEST_FILE]
source_file
Translate subtitles from one language to another.
positional arguments:
source_file The source subtitle file to translate.
options:
-h, --help show this help message and exit
--version Show the program version and exit.
--source-lang SOURCE_LANG
The language of the source subtitles (default: 'auto'). Must be a ISO 639-1:2002 language code or 'auto' to
guess.
--source-type SOURCE_TYPE
Subtitle source type (default: 'auto'). Must be either 'srt' or 'vtt', or 'auto' to guess from filename.
--dest-lang DEST_LANG
The language to translate the subtitles to (default: 'en'). Must be a ISO 639-1:2002 language code.
--dest-file DEST_FILE
The destination subtitle file (default: '..').
```
When run with any valid source file, program save translated results in in the current working directory.
General code layout:
`main.py` is the command line interface handler.
`subtitle_parser.py` handles reading, parsing, and writing subtitle files.
`translate.py` handles talking to Google Translate.
`extricate.py` (name means taking apart and putting back together) is used by the translation
module to split dictionaries into a keys list and a values list so it can translate all the
values and then rebuild the dictionary by re-combining the keys list and the new translated
values list.
`agents.py` from https://github.com/Animenosekai/useragents/blob/main/pyuseragents/data/list.py
is by Anime no Sekai and has a ton of random user agents to use so Google Translate
doesn't get suspicious of us sending tens of thousands of requests without an API key
### Links
* Source Code - https://github.com/CoolCat467/Subtitle-Translate.git
* Issues - https://github.com/CoolCat467/Subtitle-Translate/issues
### License
-------
Code and documentation are available according to the GNU General Public License v3.0 (see [LICENSE](https://github.com/CoolCat467/Subtitle-Translate/blob/HEAD/LICENSE)).