49 lines
2.2 KiB
Markdown
49 lines
2.2 KiB
Markdown
|
# MPV Subtitle Translator (SubTranslate)
|
|||
|
|
|||
|
A simple [mpv](https://mpv.io/) Lua script that uses Google Translate API calls to translate currently displayed subtitles on-the-fly.
|
|||
|
|
|||
|
## Features
|
|||
|
|
|||
|
- **Auto-detects** the source language (via `source_lang = 'auto'`).
|
|||
|
- Translates **into Russian** by default (change the `source_lang = 'ru'` parameter to any [Google Translate language code](https://cloud.google.com/translate/docs/languages)).
|
|||
|
- Displays the translation in mpv’s On-Screen Display (OSD) for a selected duration (select in options).
|
|||
|
|
|||
|
## Requirements
|
|||
|
|
|||
|
- **mpv** (tested on versions 0.29+; works with older versions if you use the custom `url_encode()` script).
|
|||
|
- **curl** (the script uses `mp.utils.subprocess` to invoke `curl`).
|
|||
|
|
|||
|
> **Note:** This script uses an **unofficial** Google Translate endpoint. Google can change or block this endpoint without notice.
|
|||
|
|
|||
|
## Installation
|
|||
|
|
|||
|
1. **Download** or create the script file: [SubTranslate.lua](./SubTranslate.lua).
|
|||
|
2. **Place** it in your mpv `scripts` folder:
|
|||
|
- **Linux/macOS**: `~/.config/mpv/scripts/`
|
|||
|
- **Windows**: `%APPDATA%\mpv\scripts\`
|
|||
|
3. **Restart** mpv (or open a new instance) so that the script loads.
|
|||
|
|
|||
|
## Usage
|
|||
|
|
|||
|
1. **Open** a video with subtitles in mpv.
|
|||
|
2. When you see a subtitle on-screen, press **Ctrl+T** (you can change this keybind in the options at the beginning of the script).
|
|||
|
3. The script sends the subtitle text to Google Translate, retrieves the translation, and displays it in the OSD.
|
|||
|
|
|||
|
## Changing the Target Language
|
|||
|
|
|||
|
- Edit the `SubTranslate.lua` file.
|
|||
|
- Look for `destination_lang = 'ru'` and change it to whatever language you want to translate
|
|||
|
|
|||
|
## Troubleshooting
|
|||
|
|
|||
|
1. **`attempt to call field 'encode_url' (a nil value)`**
|
|||
|
- Your mpv version might be too old to include `utils.encode_url()`. Try using the script version that defines a custom `url_encode()` function, or upgrade mpv to a more recent release.
|
|||
|
|
|||
|
2. **Translation Fails or Outputs Unexpected Results**
|
|||
|
- Make sure you have a working internet connection.
|
|||
|
- Check that `curl` is installed and in your system path.
|
|||
|
- The unofficial Google Translate endpoint might be down or blocked.
|
|||
|
|
|||
|
3. **Other Issues**
|
|||
|
- Run mpv from a terminal to see if there are any error messages.
|