Skip to content

fix(api-media,journeys-ui): resolve YouTube subtitle locale variants missing from dropdown#9004

Open
jianwei1 wants to merge 4 commits intomainfrom
jianweichong/nes-958-youtube-video-subtitles-language-missing-english-not-showing
Open

fix(api-media,journeys-ui): resolve YouTube subtitle locale variants missing from dropdown#9004
jianwei1 wants to merge 4 commits intomainfrom
jianweichong/nes-958-youtube-video-subtitles-language-missing-english-not-showing

Conversation

@jianwei1
Copy link
Copy Markdown
Contributor

@jianwei1 jianwei1 commented Apr 10, 2026

Summary

  • YouTube videos with locale-variant subtitle languages (e.g. en-GB, en-US, pt-BR) were silently dropped from the subtitle dropdown because the backend did exact BCP 47 matching against a Language database that only stores base codes (en, es, pt)
  • Normalizes locale-variant codes to base language before querying the Language service, with Set-based deduplication
  • Relaxes Zod trackKind validation to prevent parse failures on videos with forced caption tracks
  • Uses prefix matching in player-side subtitle activation so stored base code en correctly activates YouTube tracks reported as en-GB

Changes

Backend (apis/api-media)

  • youtube.ts: Normalize BCP 47 locale variants (en-gben) using split('-')[0] before querying language service. Deduplicate with Set. Relax Zod trackKind from z.enum(['standard', 'asr']) to z.string().
  • youtube.spec.ts: 3 new tests — locale normalization, deduplication of variants, forced track parsing

Frontend (libs/journeys/ui)

  • extractYouTubeCaptionsAndAddTextTracks.ts: Added matchesLanguageCode() helper with prefix matching (en matches en-GB but not end). Only activates first matching variant to avoid double setYouTubeCaptionTrack calls.
  • extractYouTubeCaptionsAndAddTextTracks.spec.ts: 5 new tests — locale variant matching, first-match-only, partial code safety, pt-BR matching, inverse direction safety

Test plan

  • All 13 api-media YouTube resolver tests pass (3 new)
  • All 17 extractYouTubeCaptionsAndAddTextTracks tests pass (5 new)
  • Manual: Add YouTube video with English (UK) subtitles → verify English appears in subtitle dropdown
  • Manual: Add YouTube video with English (US) subtitles → verify English appears in subtitle dropdown
  • Manual: Add YouTube video with plain English subtitles → verify still works (regression)
  • Manual: Select English subtitle → verify subtitles display during playback

Post-Deploy Monitoring & Validation

  • Log queries: Search for Invalid YouTube API response format errors — should decrease (fewer Zod parse failures from forced tracks)
  • Expected healthy signal: YouTube videos with locale-variant subtitles (en-GB, en-US) now show English in the subtitle dropdown
  • Failure signal: Any increase in Failed to fetch languages from gateway errors would indicate the normalized codes are not matching
  • Validation window: 48 hours post-deploy, spot-check 3-5 YouTube videos with known locale-variant subtitles

Closes NES-958

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed YouTube subtitle locale variants (e.g., en-GB, en-US) missing from language selection dropdowns and failing to activate during video playback. Language codes are now normalized to base languages (e.g., en) with duplicates removed for proper matching and activation of subtitle tracks regardless of locale variant.

…missing from dropdown

YouTube videos with locale-variant subtitle languages (e.g. en-GB, en-US,
pt-BR) were silently dropped from the subtitle dropdown because the backend
resolver did exact BCP 47 matching against a Language database that only
stores base codes (en, es, pt).

- Normalize locale-variant codes to base language (split on hyphen) before
  querying the Language service, with Set-based deduplication
- Relax Zod trackKind validation from enum to string to prevent parse
  failures on videos with 'forced' caption tracks
- Use prefix matching in player-side subtitle activation so stored base
  code 'en' correctly activates YouTube tracks reported as 'en-GB'
- Only activate first matching locale variant to avoid nondeterministic
  track selection from double setYouTubeCaptionTrack calls

Closes NES-958

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@linear
Copy link
Copy Markdown

linear Bot commented Apr 10, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 10, 2026

Walkthrough

Updates normalize YouTube subtitle language codes from locale variants (e.g., en-GB) to base codes (e.g., en) in API schema, relax schema validation for trackKind to accept all string values, implement prefix-based language code matching in frontend caption extraction, and add comprehensive tests and documentation for the locale variant handling fix.

Changes

Cohort / File(s) Summary
YouTube API Schema
apis/api-media/src/schema/youtube/youtube.ts, apis/api-media/src/schema/youtube/youtube.spec.ts
Changed trackKind validation from constrained enum ('standard' | 'asr') to unconstrained string type. Replaced array-based language code accumulation with Set to deduplicate base language subtags extracted from snippet.language. Added test cases verifying locale-variant normalization, deduplication, and exclusion of forced track kinds from results.
Frontend Caption Extraction Logic
libs/journeys/ui/src/components/Video/utils/extractYouTubeCaptionsAndAddTextTracks/extractYouTubeCaptionsAndAddTextTracks.ts, libs/journeys/ui/src/components/Video/utils/extractYouTubeCaptionsAndAddTextTracks/extractYouTubeCaptionsAndAddTextTracks.spec.ts
Added matchesLanguageCode() helper for prefix-based BCP-47 matching, allowing base language codes (e.g., en) to match locale variants (e.g., en-GB, en-US). Updated selection logic to mark only the first matching caption track as showing, forcing subsequent matches to hidden. Added comprehensive test cases covering variant-to-base matching, deduplication of multiple variants, and edge case coverage.
Documentation
docs/plans/2026-04-10-001-fix-youtube-subtitle-locale-variants-plan.md
New plan document specifying completed fix for missing YouTube subtitle locale variants in admin dropdown and playback activation. Details normalization requirements, schema validation relaxation, frontend matching changes, implementation checklist, and impact assessment.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing YouTube subtitle locale variants missing from the dropdown by normalizing and deduplicating locale-variant codes, and updating frontend matching logic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jianweichong/nes-958-youtube-video-subtitles-language-missing-english-not-showing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 10, 2026

Warnings
⚠️ ❗ Big PR (761 changes)

(change count - 761): Pull Request size seems relatively large. If Pull Request contains multiple changes, split each into separate PR will helps faster, easier review.

Generated by 🚫 dangerJS against 66fb75b

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 10, 2026

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution ↗ for commit 66fb75b

Command Status Duration Result
nx run journeys-e2e:e2e ❌ Failed 2m 21s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-23 23:08:21 UTC

@github-actions github-actions Bot requested a deployment to Preview - journeys April 10, 2026 02:17 Pending
@github-actions github-actions Bot requested a deployment to Preview - journeys-admin April 10, 2026 02:17 Pending
@github-actions github-actions Bot requested a deployment to Preview - resources April 10, 2026 02:17 Pending
@github-actions github-actions Bot requested a deployment to Preview - videos-admin April 10, 2026 02:17 Pending
@github-actions github-actions Bot temporarily deployed to Preview - journeys April 10, 2026 02:21 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - watch April 10, 2026 02:21 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - resources April 10, 2026 02:21 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - videos-admin April 10, 2026 02:21 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - journeys-admin April 10, 2026 02:21 Inactive
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 10, 2026

The latest updates on your projects.

Name Status Preview Updated (UTC)
journeys ✅ Ready journeys preview Mon Apr 20 11:37:13 NZST 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 10, 2026

The latest updates on your projects.

Name Status Preview Updated (UTC)
videos-admin ✅ Ready videos-admin preview Mon Apr 20 11:37:34 NZST 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 10, 2026

The latest updates on your projects.

Name Status Preview Updated (UTC)
watch ✅ Ready watch preview Mon Apr 20 11:37:50 NZST 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 10, 2026

The latest updates on your projects.

Name Status Preview Updated (UTC)
resources ✅ Ready resources preview Mon Apr 20 11:37:54 NZST 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 10, 2026

The latest updates on your projects.

Name Status Preview Updated (UTC)
journeys-admin ✅ Ready journeys-admin preview Mon Apr 20 11:38:56 NZST 2026

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/plans/2026-04-10-001-fix-youtube-subtitle-locale-variants-plan.md`:
- Line 4: The plan header's status currently says "status: completed" but
several implementation units remain unchecked and the "setYouTubeCaptionTrack"
note is outdated; change the top-level status to reflect work-in-progress (e.g.,
"in-progress" or "shipped-with-followups"), update Unit 3 to state that the
exact YouTube languageCode is now passed, and edit the "setYouTubeCaptionTrack"
note to reflect the new behavior; ensure all mentions across the document
(including the referenced ranges) consistently reflect the shipped behavior and
remaining open tasks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d0c52ba2-a8ef-4463-b1df-12261c9a5b87

📥 Commits

Reviewing files that changed from the base of the PR and between b23396c and 139c6a5.

📒 Files selected for processing (5)
  • apis/api-media/src/schema/youtube/youtube.spec.ts
  • apis/api-media/src/schema/youtube/youtube.ts
  • docs/plans/2026-04-10-001-fix-youtube-subtitle-locale-variants-plan.md
  • libs/journeys/ui/src/components/Video/utils/extractYouTubeCaptionsAndAddTextTracks/extractYouTubeCaptionsAndAddTextTracks.spec.ts
  • libs/journeys/ui/src/components/Video/utils/extractYouTubeCaptionsAndAddTextTracks/extractYouTubeCaptionsAndAddTextTracks.ts

---
title: 'fix: YouTube subtitle locale variants missing from dropdown'
type: fix
status: completed
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Align the completed plan with the shipped behavior.

status: completed conflicts with the unchecked implementation units, and the setYouTubeCaptionTrack note still says no change is needed even though Unit 3 now describes passing the exact YouTube languageCode. Updating those sections will keep future readers from treating this as still-open work.

Also applies to: 56-66, 70-143, 156-163

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/plans/2026-04-10-001-fix-youtube-subtitle-locale-variants-plan.md` at
line 4, The plan header's status currently says "status: completed" but several
implementation units remain unchecked and the "setYouTubeCaptionTrack" note is
outdated; change the top-level status to reflect work-in-progress (e.g.,
"in-progress" or "shipped-with-followups"), update Unit 3 to state that the
exact YouTube languageCode is now passed, and edit the "setYouTubeCaptionTrack"
note to reflect the new behavior; ensure all mentions across the document
(including the referenced ranges) consistently reflect the shipped behavior and
remaining open tasks.

@blacksmith-sh

This comment has been minimized.

@jianwei1 jianwei1 self-assigned this Apr 14, 2026
@github-actions github-actions Bot temporarily deployed to Preview - journeys April 14, 2026 20:33 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - journeys-admin April 14, 2026 20:33 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - resources April 14, 2026 20:33 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - videos-admin April 14, 2026 20:33 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - watch April 19, 2026 23:35 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - videos-admin April 19, 2026 23:35 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - resources April 19, 2026 23:35 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - journeys April 19, 2026 23:35 Inactive
@github-actions github-actions Bot temporarily deployed to Preview - journeys-admin April 19, 2026 23:35 Inactive
@blacksmith-sh
Copy link
Copy Markdown
Contributor

blacksmith-sh Bot commented Apr 19, 2026

Found 1 test failure on Blacksmith runners:

Failure

Test View Logs
src/e2e/journeys.spec.ts/journeys View Logs

Fix in Cursor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant