Languages

Translates the controls and sets their text direction.

import { i18n } from "react-video-kit/i18n";

Adds 261 B to a player332 B on its ownSource

Translates every label in the controls, and sets the player's language and text direction. Switch the demo to Arabic, then hover a control to read its label, or open the settings menu.

0:00−0:000:00

Hover a control to read its label, or open the settings menu. In Arabic the controls swap sides, while the timeline and volume slider keep running left to right.

Usage

tsx
import { i18n } from "react-video-kit/i18n";import { ar } from "react-video-kit/i18n/ar";import { VideoPlayer } from "react-video-kit/player";const plugins = [i18n({ locale: "ar", strings: ar })];<VideoPlayer src="/video.mp4" plugins={plugins} />;

locale is a BCP 47 tag, such as ar or pt-BR. Text direction comes from it, and dir overrides that:

tsx
i18n({ locale: "ar", strings: ar, dir: "ltr" });

Locales that ship

LanguageImport
Arabicimport { ar } from "react-video-kit/i18n/ar"
Spanishimport { es } from "react-video-kit/i18n/es"
Frenchimport { fr } from "react-video-kit/i18n/fr"

Each is its own entry, so the ones you don't import stay out of your bundle. English is built into the parts, and needs no import. None of the three translates airplay, so that label stays "AirPlay".

Supply your own strings

Pass any of the strings below. Anything you leave out falls back to English.

tsx
import { i18n, type Strings } from "react-video-kit/i18n";const de: Strings = {  play: "Abspielen",  pause: "Pause",  mute: "Stumm",  unmute: "Ton an",};i18n({ locale: "de", strings: de });

To change a few strings in a shipped locale, spread it:

tsx
import { i18n } from "react-video-kit/i18n";import { fr } from "react-video-kit/i18n/fr";i18n({ locale: "fr", strings: { ...fr, cancel: "Non merci" } });

These are all the strings the built-in parts and plugins read:

Every string the built-in parts and plugins show or announce.

FieldTypeDescription
play?stringThe label on the play buttons, and the hotkey message for playing.
pause?stringThe label on the play button during playback, and the hotkey message for pausing.
replay?stringThe label on the play buttons once the video has ended.
seekBack?stringThe label on a backward seek button, where {seconds} stands for the amount.
seekForward?stringThe label on a forward seek button, where {seconds} stands for the amount.
seek?stringThe label on the timeline's slider.
of?stringThe word between the two times the timeline announces, as in 1:00 of 5:00.
mute?stringThe label on the mute button while the sound is on.
unmute?stringThe label on the mute button while muted.
muted?stringThe hotkey message after muting.
unmuted?stringThe hotkey message after unmuting.
volume?stringThe label on the volume slider, and the start of the hotkey message for volume.
settings?stringThe label on the settings menu button.
player?stringThe name of the player itself, for screen readers, where it has no other.
buffering?stringAnnounced when the video has been stalled for a few seconds.
transcript?stringThe name of the transcript's list of lines.
back?stringThe label on the back row of a submenu.
fullscreen?stringThe label on the fullscreen button outside fullscreen.
exitFullscreen?stringThe label on the fullscreen button while in fullscreen.
pip?stringThe label on the picture-in-picture button outside picture-in-picture.
exitPip?stringThe label on the picture-in-picture button while in picture-in-picture.
error?stringThe title on the error overlay when a video can't be played.
errorDetail?stringThe line under that title.
errorConnection?stringThe title on the error overlay when trying again could work.
errorConnectionDetail?stringThe line under that title.
errorProtected?stringThe title on the error overlay when protected video can't be played.
errorProtectedDetail?stringThe line under that title.
errorDenied?stringThe title on the error overlay when the viewer isn't allowed to watch.
errorDeniedDetail?stringThe line under that title.
errorOutput?stringThe title on the error overlay when protection rules out this display.
errorOutputDetail?stringThe line under that title.
errorCode?stringThe words before the code on the error overlay, with their punctuation.
retry?stringThe label on the error overlay's retry button.
speed?stringThe name of the speed row and its submenu in the settings menu.
normal?stringThe name of the 1× rate in the speed menu.
quality?stringThe name of the quality row and its submenu in the settings menu.
auto?stringThe name of the automatic choice in the quality menu.
captions?stringThe label on the captions button, and the name of the captions row in the settings menu.
captionsOff?stringThe name of the off choice in the captions menu.
audio?stringThe name of the audio row and its submenu in the settings menu.
chapters?stringThe name of the chapters row and its submenu in the settings menu.
tapToUnmute?stringThe text on the chip offering sound after a muted autoplay.
live?stringThe text on the live indicator.
goLive?stringThe label on the live indicator when behind the edge or paused.
next?stringThe label on the playlist's next button.
previous?stringThe label on the playlist's previous button.
upNext?stringThe heading on the up-next card.
playNow?stringThe label on the up-next card's button that plays the next item.
cancel?stringThe label on the up-next card's button that stays on the finished video.
airplay?stringThe label on the AirPlay button.
cast?stringThe label on the Cast button.
castingTo?stringThe text before the device name on the casting overlay.
ad?stringThe word before the count and time left on the ad overlay.
skipAd?stringThe label on the ad overlay's skip button once skipping is allowed.
skipAdIn?stringThe text before the seconds on the skip button until skipping is allowed.
learnMore?stringThe text on the ad overlay's link.
episodes?stringThe label on the episodes button and shelf.
nowPlaying?stringMarks the episode that's playing on the shelf.
close?stringThe label on a panel's close button.
info?stringThe label on the info button and panel.
skipIntro?stringThe skip button during an intro.
skipRecap?stringThe skip button during a recap.
skipCredits?stringThe skip button during credits, with nothing to move on to.
skip?stringThe skip button during any other part.
nextEpisode?stringThe skip button during credits, with another item in the playlist.
ambient?stringThe name of the ambient light row in the settings menu.
backToVideo?stringThe label on the mini player's button that scrolls back to the video.
screenshot?stringThe name of the row that saves the current frame.
screenshotSaved?stringThe message after saving a frame.
screenshotFailed?stringThe message when a frame can't be saved.
loop?stringThe name of the loop row and its submenu in the settings menu.
loopVideo?stringThe choice in the loop menu that repeats the whole video.
loopStart?stringThe row in the loop menu that starts a section at the current position.
loopEnd?stringThe row in the loop menu that ends a section at the current position.
shortcuts?stringThe title of the shortcuts list, and its row in the settings menu.
shortcutPlayPause?stringThe name of the play and pause shortcut.
shortcutVolumeUp?stringThe name of the shortcut that raises the volume.
shortcutVolumeDown?stringThe name of the shortcut that lowers the volume.
shortcutMute?stringThe name of the mute shortcut.
shortcutFaster?stringThe name of the shortcut that speeds playback up.
shortcutSlower?stringThe name of the shortcut that slows playback down.
shortcutStart?stringThe name of the shortcut to the start.
shortcutEnd?stringThe name of the shortcut to the end.
shortcutJump?stringThe name of the number keys, which jump through the video.
stats?stringThe title of the stats readout, and its row in the settings menu.
statsVideo?stringThe stats row for the picture's size.
statsViewport?stringThe stats row for the player's size on the page.
statsFrames?stringThe stats row for dropped frames.
statsBuffer?stringThe stats row for how much is downloaded ahead.
statsEngine?stringThe stats row for the active provider.
statsLatency?stringThe stats row for the distance from the live edge.
copy?stringThe label on the stats readout's copy button.
copied?stringThe label on that button just after copying.
share?stringThe label on the share button.
linkCopied?stringThe message after copying a link.
linkFailed?stringThe message when a link can't be copied.
fill?stringThe label on the fit button while the whole picture shows.
fitWhole?stringThe label on the fit button while the picture fills the frame.
transcriptResume?stringThe label on the transcript's button that returns to the current line.

A few aren't button labels. of joins the times a screen reader hears on the timeline, as in "0:05 of 0:30". muted and unmuted confirm the m key in the hotkeys plugin. skipAdIn and castingTo come before a number and a device name. seekBack and seekForward name the buttons on either side of play, and {seconds} in them becomes the distance. back names the row that leaves a settings submenu, for screen readers.

Switch language while playing

The demo gives the player a key, which makes a new player and restarts the video. setLocale changes language without interrupting playback:

tsx
"use client";import { useCommands } from "react-video-kit";import { i18n } from "react-video-kit/i18n";import { fr } from "react-video-kit/i18n/fr";function SwitchToFrench() {  const { setLocale } = useCommands(i18n);  return <button onClick={() => setLocale("fr", fr)}>Français</button>;}

It replaces the current strings rather than merging into them, and works out the direction again unless you pass one as the third argument.

Translate your own parts

useLabel returns the current translation, or your fallback when there's none or the plugin isn't installed:

tsx
"use client";import { useLabel } from "react-video-kit";function PlayLabel() {  const label = useLabel("play", "Play");  return <span>{label}</span>;}

What mirrors

dir and lang go on the player's root element, so they're already right in the server's HTML. The default skin follows dir for layout, but some things stay fixed.

These mirror in a right-to-left language:

  • The control row and everything in it. Play sits on the right and settings on the left.
  • The time readout, with the current time on the right of the duration.
  • The left and right arrow keys in menus, which swap between opening a submenu and going back.
  • The settings menu, which opens from the left, above its button.

These don't:

  • The timeline and the volume slider, which set dir="ltr". They fill from left to right, and the right arrow key still moves forward.
  • The left and right arrow keys in the hotkeys plugin. Left always seeks back.
  • Double-tap in the gestures plugin. The left half always seeks back.
  • Icons, which aren't flipped.
  • The up-next card, which stays on the right, and the unmute chip, which stays at the top left.
  • Times, which stay in Western digits.

Behaviour

  • These languages get rtl automatically: ar, dv, fa, he, ks, ps, sd, ug, ur, and yi. Only the language part of the tag counts, so ar-EG is rtl and pt-BR is ltr.
  • Some text sits outside Strings: the detail line on the error overlay, which comes from the browser or the provider, and short readouts such as +10s.

API

Options

OptionTypeDescription
localestringA BCP 47 tag, such as "ar" or "pt-BR".
strings?StringsStrings for that locale. Anything missing falls back to English.
dir?"ltr" | "rtl"Text direction. Worked out from locale when not given.

State

Read it with useVideoState(i18n, (state) => …).

FieldTypeDescription
localestringThe current language, written to Root as lang.
stringsRecord<string, string>Translations for that language, where anything missing falls back to English.
dir"ltr" | "rtl"The text direction, written to Root as dir.

Commands

Call them with useCommands(i18n).

CommandTypeDescription
setLocale(locale: string, strings?: Strings, dir?: "ltr" | "rtl") => voidSwitches language while playing.