Dev.to WebDev 🛠 Dev 👁 0 📖 4 min read

Localizing YouTube videos with the Data API v3: what the official docs say about titles, descriptions, captions and quota

YouTube can show a viewer the title and description of a video in the viewer's own language, and it can offer subtitles in many languages. Both are part of the public YouTube Data API v3. This post walks through what the

YouTube can show a viewer the title and description of a video in the viewer's own language, and it can offer
subtitles in many languages. Both are part of the public YouTube Data API v3. This post walks through what the official
documentation says about each piece, with links, and the details that are easy to miss when you read it for the first
time.

Two separate things: localized metadata and caption tracks

The API keeps translated text in two different places:

  • Localized metadata: the localizations property of a video. The Videos resource describes it as a map from a language code to a localized title and description. YouTube shows the version that matches the viewer's language.
  • Caption tracks: separate Captions resources, one per language, each with its own timing. They have their own methods (captions.list, captions.download, captions.insert, captions.update).

They are different endpoints with different permissions and very different quota costs, so it helps to plan them as two
jobs.

Titles and descriptions: videos.update with localizations

From the videos.update reference and the Videos
resource:

  • Localizations need a default language. The docs tie localizations to snippet.defaultLanguage, the language of the original title and description. Set it before adding translations.
  • An update replaces what you send. The videos.update page warns that properties you leave out of an updated part lose their existing values. For localizations that means the map you send becomes the full set, so read the current values first and send them back together with the new language.
  • snippet is all or nothing. If the request includes the snippet part, the docs list title and categoryId as required. Send back the snippet you read.

Playlists have the same localizations property, with
the same rules.

Caption tracks: list, download, insert or update

From the Captions reference:

  1. captions.list returns the tracks of a video. Each has a language and a trackKind: standard for a regular track, ASR for one made by YouTube's automatic speech recognition, and forced for forced-only captions.
  2. captions.download returns the track text. The tfmt parameter picks the format (srt, vtt, sbv, scc, ttml), and tlang asks YouTube for a machine translation of the track. The docs say the method requires permission to edit the video.
  3. captions.insert uploads a new track for a language; captions.update updates an existing one. Check captions.list first, or the video ends up with two tracks in the same language.

A practical note on subtitle files: an SRT file is numbered cues, each with a timestamp line and text. When the text is
translated, keep the timestamps and the number of cues as they were; only the text lines should change.

The quota bill

The quota cost table says a project gets 10,000 units
a day by default for most endpoints. At the time of writing it lists 1 unit for videos.list, 50 for captions.list
and videos.update, 400 for captions.insert and 450 for captions.update; the captions.download page gives 200
units. Check the current numbers before you plan around them.

What follows from the table:

  • Titles and descriptions for one video in 20 languages fit into one videos.update, because all languages go into the same localizations map: 50 units.
  • Subtitles for the same video in 20 languages are 20 captions.insert calls: 8,000 units, most of a default day.
  • So put every language of a video into one metadata update, skip languages that already exist, and request a quota extension early through the quota and compliance audit.

Language codes

YouTube uses BCP-47 style language codes, and the region or script matters: pt-BR and pt-PT, zh-Hans and
zh-Hant, es-419 and es. Use the same code for the localization and for the caption track, so a
viewer gets both.

Why it matters for a channel

For a creator this is not an engineering detail. A title and description in the viewer's language is what that viewer
sees in search, in recommendations and on the watch page; subtitles in their language are what lets them follow the
video. A channel that only has its original language competes for one audience. The same video with localized metadata
and subtitle tracks can be found and understood in many more countries, and some of those markets pay more per 1,000
views than the creator's home market.

Doing this by hand in YouTube Studio means one language and one video at a time, which is why most channels never
localize past one or two languages. Following the documentation above, we implemented this flow in
Creator Tools, a YouTube metadata translator for titles, descriptions and subtitles:
it translates the metadata and existing subtitle tracks of many videos at once and writes them to the channel in 140+
languages.

Sources

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.