MPV subtitle translation plugin
Go to file
2025-01-16 21:09:27 +05:00
README.md changing default keybind 2025-01-16 21:09:27 +05:00
SubTranslate.lua changing default keybind 2025-01-16 21:09:27 +05:00

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 mpvs 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.
  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 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.