2.2 KiB
2.2 KiB
MPV Subtitle Translator (SubTranslate)
A simple mpv 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). - 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 invokecurl
).
Note: This script uses an unofficial Google Translate endpoint. Google can change or block this endpoint without notice.
Installation
- Download or create the script file: SubTranslate.lua.
- Place it in your mpv
scripts
folder:- Linux/macOS:
~/.config/mpv/scripts/
- Windows:
%APPDATA%\mpv\scripts\
- Linux/macOS:
- Restart mpv (or open a new instance) so that the script loads.
Usage
- Open a video with subtitles in mpv.
- When you see a subtitle on-screen, press T (you can change this keybind in the options at the beginning of the script).
- 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
-
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 customurl_encode()
function, or upgrade mpv to a more recent release.
- Your mpv version might be too old to include
-
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.
-
Other Issues
- Run mpv from a terminal to see if there are any error messages.