WebVTT
Translate WebVTT caption and subtitle cues in place, keeping the header, identifiers, timings, cue settings and comments byte for byte.
WebVTT is the caption and subtitle format of the web's <track> element and of most video platforms. The vtt file handler translates the text of each cue and writes it into a copy of the source file, so the header, cue identifiers, timings, cue settings such as align:start position:0%, and NOTE, STYLE and REGION blocks stay as they were, along with a byte order mark and the file's line endings. Only cue text changes. The handler does not retime cues, so a translation still has to fit its cue's interval.
SubRip .srt files have their own format, SubRip. The two formats write timings and tags differently, so keep each file in its own format.
Configure WebVTT translation #
A .vtt file belongs only to an entry whose pattern ends in .vtt, or one that sets "format": "vtt", and such an entry selects only .vtt files. A broad pattern such as media/en/**/* therefore skips captions, and an entry with "format": "vtt" skips the videos beside them:
{
"sourceLocale": "en",
"targetLocales": ["de", "fr"],
"files": [{ "pattern": "captions/en/*.vtt" }]
}This writes captions/de/intro.vtt and captions/fr/intro.vtt for captions/en/intro.vtt. Target paths follow the same rules as JSON, described under output paths, and targetPath declares any other layout. The same configuration works in the CLI, from version 1.25.0, and in the GitHub App.
What is translated #
Each cue that has text is one unit, all of its lines together:
WEBVTT
Kind: captions
Language: en
NOTE Recorded for the spring release.
intro
00:00:01.000 --> 00:00:04.000 align:start position:10%
<v Ana>Welcome to the <b>new</b> dashboard.</v>
00:00:04.500 --> 00:00:07.000
Your reports are on the left,
your team is on the right.Here the two cues are two units. The header with its Kind and Language lines, the NOTE, the identifier intro, the timings and the cue settings are not sent for translation.
- Cue tags.
<i>,<b>,<u>, class spans such as<c.yellow>, voice spans such as<v Ana>, language spans such as<lang en-GB>, and<ruby>with<rt>go to the model as placeholders it can move but not change, so the translation can putnewwhere the target language needs it. Timestamp tags such as<00:00:02.250>, which karaoke-style captions use, and tags that WebVTT does not define are placeholders too. Each tag is written back exactly as the source wrote it, classes and annotation included. A span the source leaves open, such as a<b>that runs to the end of the cue, is closed with its end tag when a translation changes the cue, so the text after it stays outside the span. - References.
&,<,>and numeric references such aséare decoded before translation. Other named references, such as or‎, and and , which would otherwise break the cue's lines, are protected like placeholders and written back as they are. - Lines. The line breaks inside a cue are part of its unit, so the model sees where the captioner broke the text and can break the translation to fit. Spaces at the end of a cue stay in the file and are not sent.
- Values that are not prose. A cue that is only digits, a URL, an ISO date or a 22-character identifier of letters and digits is copied into every target instead of being translated.
- Cues without text. A cue with no text, or with only tags, references such as
and whitespace, sends nothing and stays in every target as it is.
The handler does not change a Language line in the header or any other header metadata. If your player reads it, update it in your build.
How translations are written #
A translation replaces only its cue's text. &, < and > in a translation are escaped, so a translated --> is written as --> and cannot start a new cue, and a < cannot open a tag. Line breaks in a translation are written with the file's own line ending, CRLF or a lone CR included, and spaces, tabs and line breaks around a translation are dropped. Other spaces, such as a no-break or ideographic space, are kept.
A blank line would end a cue early, so a translation that holds one is refused. So is a translation with no text, even if it keeps its cue's tags and references, and one that leaves out or repeats a tag or reference of its cue, or moves a tag into or out of another, such as an <rt> out of its <ruby>. The target for that locale then fails, naming the cue and the reason, and nothing is written for it.
Keys and reuse #
Each unit is keyed by its cue identifier, kept whole as written, such as intro or intro#2. A cue without an identifier is keyed by its position among the cues: 1, 2, 3. An identifier that repeats in the file is numbered, so a second intro becomes intro#1. These keys name units in the job and in Studio.
A cue keeps its existing translation while its text, tags included, is unchanged since the last push, so changing only a tag, such as <i> to <b>, translates the cue again. Cues are matched by their text and their place in the sequence of cues, not by their keys, so shifted timings, a renamed identifier or an inserted cue keep the translations of the cues around them, and only new or changed cues are translated. A translation whose tags a translator reordered, as the target language's word order often needs, is kept too. A translation whose tags or references no longer match its cue's is translated again, and so is a cue a translator emptied in the target, while the cues around it keep their translations. A cue that repeats word for word in the file keeps its translation only while the number of cues and its position stay the same, so the translations of two repeats cannot swap.
A target whose cues no longer line up with the previous source, for example because someone merged two cues in it, supplies no translations, and a target cue whose identifier or times differ from the previous source's cue at its place supplies none for that cue. Keep the previous source paired with its accepted target when you insert, split or move cues.
Options that do not apply #
WebVTT cues have no named keys and no attributes to translate. The CLI and the GitHub App refuse a vtt entry that sets lockedKeys, preservedKeys, ignoredKeys, keyColumn, injectLocale, translateFrontmatterFields, translateComponentProps or translateJSXProps, because the file would otherwise be translated as if the option were not set. lockedPatterns is refused as for every format other than Java properties.
lingo push --key skips vtt files with a message and pushes the other selected files, and /lingo translate --key in the GitHub App skips them too.
Invalid WebVTT #
A file must start with a WEBVTT line, after an optional byte order mark. After the header, each block must be a cue, whose timing line reads like 00:00:01.000 --> 00:00:04.000 or 00:01.000 --> 00:04.000 without hours, or a NOTE, STYLE or REGION block. A file fails with the line of the first problem when:
- the
WEBVTTline is missing; - a timing is malformed, for example
00:00:01,000with SubRip's comma, minutes or seconds past 59, or milliseconds that are not three digits; - a block is neither a cue nor a
NOTE,STYLEorREGIONblock, for example a timing line written with->, or the rest of a cue after a blank line inside it; - a line inside cue text or a
NOTEorSTYLEblock holds-->, which only a timing line may hold. In cue text, write it as-->.
Players skip such a block silently, which usually hides a mistake, so the handler stops at it instead. Nothing is written for that file, and an existing target stays as it is. A target that is not valid fails the same way, with its locale named. Fix the file, then push again.
Cues whose timings are out of order, a timing line with no blank line before it, and blocks of only spaces and tabs are read the way players read them.