static updateTextTracks(tracks, langMenu, onTrackSelected, updateChosen,
      currentSelectionElement, localization, trackLabelFormat) {
    const LocIds = shaka.ui.Locales.Ids;

    // TODO: Do the benefits of having this common code in a method still
    // outweigh the complexity of the parameter list?
    const selectedTrack = tracks.find((track) => {
      return track.active == true;
    });

    // Remove old tracks
    // 1. Save the back to menu button
    const backButton = shaka.ui.Utils.getFirstDescendantWithClassName(
        langMenu, 'shaka-back-to-overflow-button');

    // 2. Remove everything
    shaka.util.Dom.removeAllChildren(langMenu);

    // 3. Add the backTo Menu button back
    langMenu.appendChild(backButton);

    // 4. Figure out which languages have multiple roles.
    const getRolesString = (track) => {
      return track.roles.join(', ');
    };

    const getCombination = (language, rolesString, label) => {
      const keys = [
        language,
        rolesString,
      ];
      if (label &&
          trackLabelFormat == shaka.ui.Overlay.TrackLabelFormat.LABEL) {
        keys.push(label);
      }
      return keys.join(': ');
    };

    // 5. Add new buttons
    /** @type {!Set<string>} */
    const combinationsMade = new Set();
    const selectedCombination = selectedTrack ? getCombination(
        selectedTrack.language, getRolesString(selectedTrack),
        selectedTrack.label) : '';

    for (const track of tracks) {
      const language = track.language;
      const forced = track.forced;
      const forcedString = localization.resolve(LocIds.SUBTITLE_FORCED);
      const rolesString = getRolesString(track);
      const label = track.label;
      const combinationName =
          getCombination(language, rolesString, label);
      if (combinationsMade.has(combinationName)) {
        continue;
      }
      combinationsMade.add(combinationName);

      const button = shaka.util.Dom.createButton();
      button.addEventListener('click', () => {
        onTrackSelected(track);
      });

      const span = shaka.util.Dom.createHTMLElement('span');
      button.appendChild(span);

      span.textContent =
          shaka.ui.LanguageUtils.getLanguageName(language, localization);
      switch (trackLabelFormat) {
        case shaka.ui.Overlay.TrackLabelFormat.LANGUAGE:
          if (forced) {
            span.textContent += ' (' + forcedString + ')';
          }
          break;
        case shaka.ui.Overlay.TrackLabelFormat.ROLE:
          if (!rolesString) {
            // Fallback behavior. This probably shouldn't happen.
            shaka.log.alwaysWarn('Track #' + track.id + ' does not have a ' +
                'role, but the UI is configured to only show role.');
            span.textContent = '?';
          } else {
            span.textContent = rolesString;
          }
          if (forced) {
            span.textContent += ' (' + forcedString + ')';
          }
          break;
        case shaka.ui.Overlay.TrackLabelFormat.LANGUAGE_ROLE:
          if (rolesString) {
            span.textContent += ': ' + rolesString;
          }
          if (forced) {
            span.textContent += ' (' + forcedString + ')';
          }
          break;
        case shaka.ui.Overlay.TrackLabelFormat.LABEL:
          if (label) {
            span.textContent = label;
          } else {
            // Fallback behavior. This probably shouldn't happen.
            shaka.log.alwaysWarn('Track #' + track.id + ' does not have a ' +
                'label, but the UI is configured to only show labels.');
            span.textContent = '?';
          }
          break;
      }

      if (updateChosen && (combinationName == selectedCombination)) {
        button.appendChild(shaka.ui.Utils.checkmarkIcon());
        span.classList.add('shaka-chosen-item');
        button.ariaSelected = 'true';
        currentSelectionElement.textContent = span.textContent;
      }
      langMenu.appendChild(button);
    }
  }
@param {!Array<shaka.extern.TextTrack>} tracks
@param {!HTMLElement} langMenu
@param {function(!shaka.extern.TextTrack)} onTrackSelected
@param {boolean} updateChosen
@param {!HTMLElement} currentSelectionElement
@param {shaka.ui.Localization} localization
@param {shaka.ui.Overlay.TrackLabelFormat} trackLabelFormat