Skip to content

feat(react): add i18n provider and wire UI labels#1595

Open
sampotts wants to merge 31 commits into
feat/i18n-htmlfrom
feat/i18n-react
Open

feat(react): add i18n provider and wire UI labels#1595
sampotts wants to merge 31 commits into
feat/i18n-htmlfrom
feat/i18n-react

Conversation

@sampotts

@sampotts sampotts commented May 25, 2026

Copy link
Copy Markdown
Collaborator

Refs #222
Closes #1364

Summary

  • Adds React I18nProvider, hooks, and wires skin control labels through useTranslator
  • Composes i18n on Container with nested-provider passthrough for explicit locales
  • Resolves langRootRef under ambient ancestor providers

Test plan

  • pnpm -F @videojs/react test src/i18n
  • Package typecheck

Stacked on #1591.

Made with Cursor


Note

Medium Risk
Touches accessibility strings across many controls and async locale loading; behavior is well tested but regressions in aria-labels or locale edge cases are possible.

Overview
Adds a React i18n layer (createI18n, default I18nProvider, useTranslator, useLocale) that merges registry, lazy built-in locale packs, props, and optional browser fallbacks, with locale from props, DOM lang (via langRootRef / ambient subscription), and nested-provider passthrough.

Container wraps the player shell in I18nProvider with langRootRef so skins inherit locale without extra setup. Package exports add @videojs/react/i18n and per-locale build entries.

UI controls and dialogs now resolve labels through resolveControlLabel / resolveControlAttrs and core phrase helpers (ErrorDialog title/description/close, time remaining, input-indicator labels). Presets drop hard-coded error dialog copy in favor of those components. Tests cover provider behavior, play button aria-label, and translated error dialog.

Reviewed by Cursor Bugbot for commit f12eb04. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented May 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
v10-sandbox Ready Ready Preview, Comment Jul 3, 2026 4:15am

Request Review

Comment thread packages/react/src/i18n/create-i18n.tsx Outdated
Comment thread packages/react/src/i18n/create-i18n.tsx
Comment thread packages/react/src/i18n/create-i18n.tsx
sampotts and others added 30 commits July 3, 2026 13:53
Wrap the player Provider with I18nProvider so preset skins inherit locale
and lazy locale loading, and restore English ARIA expectations in tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
Let outer I18nProvider (sandbox locale) win over player chrome, and skip
nested default providers so locale props are not shadowed.

Co-authored-by: Cursor <cursoragent@cursor.com>
Pass langRootRef from Container for ambient lang resolution, fall back to
documentElement before mount, and inherit ancestor locale when a nested
provider only supplies translation overrides.

Co-authored-by: Cursor <cursoragent@cursor.com>
Only pass locale to I18nProviderRoot when a value is resolved so nested
providers do not assign undefined under exactOptionalPropertyTypes.

Co-authored-by: Cursor <cursoragent@cursor.com>
Re-check lazy-load sequence after getBrowserTranslations resolves so a
superseded locale cannot register browser translations globally.

Co-authored-by: Cursor <cursoragent@cursor.com>
Container's langRootRef no longer forces a nested provider that shadows
an ancestor locale or translations prop.

Co-authored-by: Cursor <cursoragent@cursor.com>
Track whether a provider locale came from an explicit prop so Container's
langRootRef still resolves player shell lang when a test or app wrapper
supplies an ambient ancestor provider.

Co-authored-by: Cursor <cursoragent@cursor.com>
Adds regression tests for document.documentElement.lang updates on
I18nProvider with and without langRootRef.

Co-authored-by: Cursor <cursoragent@cursor.com>
Use mergeLocaleOverlays loadedTags instead of merged overlay so
English-only lazy merges no longer block browser translation fallback.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

2 participants