Auto-Translation of <track> elements

What It Does

Loads subtitles from a <track> element, then sends them to Google Translate to be translated into languages you specify. It also allows the user to choose additional languages. Thanks to Playr for the original SRT parsing code.



Video with <track> element

Be sure to set the srclang attribute

<video width="320" height="240" poster="poster.jpg" controls="controls" preload="none">
	<!-- MP4 file (you can also add WebM and Ogg if needed -->
	<source type="video/mp4" src="myvideo.mp4" />
	<!-- Optional: Add subtitles for each language -->
	<track kind="subtitles" src="" srclang="en" />

Add Script and Styles

Add the normal JavaScript and stylesheet

<script src="jquery.js"></script>
<script src="mediaelement-and-player.min.js"></script>
<link rel="stylesheet" href="mediaelementplayer.css" />
<!-- translation is built is, so no additional plugins are needed -->

Choose Options

Captions are automatically added, but you can control where they appear on the control bar with the 'track' option, and you can also set a default langauge

jQuery(document).ready(function($) {

		// automatically create these translations on load
		// allow the user to add additional translations
		translationSelector: true,
		// start with English automatically turned on
		startLanguage: 'en'