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.
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.
"use client";import { useMemo, useState } from "react";import { i18n } from "react-video-kit/i18n";import { ar } from "react-video-kit/i18n/ar";import { defaultPlugins, VideoPlayer } from "react-video-kit/player";const button = "rounded-md border border-current px-3 py-1.5 text-sm text-current aria-pressed:font-semibold aria-pressed:underline";export default function Languages() { const [locale, setLocale] = useState("en"); const plugins = useMemo( () => [i18n({ locale, strings: locale === "ar" ? ar : {} }), ...defaultPlugins()], [locale] ); return ( <div className="flex flex-col gap-3"> <div role="group" aria-label="Language" className="flex gap-2"> <button type="button" className={button} aria-pressed={locale === "en"} onClick={() => setLocale("en")}> English </button> <button type="button" className={button} aria-pressed={locale === "ar"} onClick={() => setLocale("ar")}> Arabic </button> </div> {/* A player reads `plugins` once, so the key makes a new one for each language. */} <VideoPlayer key={locale} src="/media/sample-720.mp4" poster="/media/poster.jpg" plugins={plugins} load="visible" /> <p className="text-sm text-current opacity-80"> 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. </p> </div> );}Usage
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:
i18n({ locale: "ar", strings: ar, dir: "ltr" });Locales that ship
| Language | Import |
|---|---|
| Arabic | import { ar } from "react-video-kit/i18n/ar" |
| Spanish | import { es } from "react-video-kit/i18n/es" |
| French | import { 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.
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:
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.
| Field | Type | Description |
|---|---|---|
| play? | string | The label on the play buttons, and the hotkey message for playing. |
| pause? | string | The label on the play button during playback, and the hotkey message for pausing. |
| replay? | string | The label on the play buttons once the video has ended. |
| seekBack? | string | The label on a backward seek button, where {seconds} stands for the amount. |
| seekForward? | string | The label on a forward seek button, where {seconds} stands for the amount. |
| seek? | string | The label on the timeline's slider. |
| of? | string | The word between the two times the timeline announces, as in 1:00 of 5:00. |
| mute? | string | The label on the mute button while the sound is on. |
| unmute? | string | The label on the mute button while muted. |
| muted? | string | The hotkey message after muting. |
| unmuted? | string | The hotkey message after unmuting. |
| volume? | string | The label on the volume slider, and the start of the hotkey message for volume. |
| settings? | string | The label on the settings menu button. |
| player? | string | The name of the player itself, for screen readers, where it has no other. |
| buffering? | string | Announced when the video has been stalled for a few seconds. |
| transcript? | string | The name of the transcript's list of lines. |
| back? | string | The label on the back row of a submenu. |
| fullscreen? | string | The label on the fullscreen button outside fullscreen. |
| exitFullscreen? | string | The label on the fullscreen button while in fullscreen. |
| pip? | string | The label on the picture-in-picture button outside picture-in-picture. |
| exitPip? | string | The label on the picture-in-picture button while in picture-in-picture. |
| error? | string | The title on the error overlay when a video can't be played. |
| errorDetail? | string | The line under that title. |
| errorConnection? | string | The title on the error overlay when trying again could work. |
| errorConnectionDetail? | string | The line under that title. |
| errorProtected? | string | The title on the error overlay when protected video can't be played. |
| errorProtectedDetail? | string | The line under that title. |
| errorDenied? | string | The title on the error overlay when the viewer isn't allowed to watch. |
| errorDeniedDetail? | string | The line under that title. |
| errorOutput? | string | The title on the error overlay when protection rules out this display. |
| errorOutputDetail? | string | The line under that title. |
| errorCode? | string | The words before the code on the error overlay, with their punctuation. |
| retry? | string | The label on the error overlay's retry button. |
| speed? | string | The name of the speed row and its submenu in the settings menu. |
| normal? | string | The name of the 1× rate in the speed menu. |
| quality? | string | The name of the quality row and its submenu in the settings menu. |
| auto? | string | The name of the automatic choice in the quality menu. |
| captions? | string | The label on the captions button, and the name of the captions row in the settings menu. |
| captionsOff? | string | The name of the off choice in the captions menu. |
| audio? | string | The name of the audio row and its submenu in the settings menu. |
| chapters? | string | The name of the chapters row and its submenu in the settings menu. |
| tapToUnmute? | string | The text on the chip offering sound after a muted autoplay. |
| live? | string | The text on the live indicator. |
| goLive? | string | The label on the live indicator when behind the edge or paused. |
| next? | string | The label on the playlist's next button. |
| previous? | string | The label on the playlist's previous button. |
| upNext? | string | The heading on the up-next card. |
| playNow? | string | The label on the up-next card's button that plays the next item. |
| cancel? | string | The label on the up-next card's button that stays on the finished video. |
| airplay? | string | The label on the AirPlay button. |
| cast? | string | The label on the Cast button. |
| castingTo? | string | The text before the device name on the casting overlay. |
| ad? | string | The word before the count and time left on the ad overlay. |
| skipAd? | string | The label on the ad overlay's skip button once skipping is allowed. |
| skipAdIn? | string | The text before the seconds on the skip button until skipping is allowed. |
| learnMore? | string | The text on the ad overlay's link. |
| episodes? | string | The label on the episodes button and shelf. |
| nowPlaying? | string | Marks the episode that's playing on the shelf. |
| close? | string | The label on a panel's close button. |
| info? | string | The label on the info button and panel. |
| skipIntro? | string | The skip button during an intro. |
| skipRecap? | string | The skip button during a recap. |
| skipCredits? | string | The skip button during credits, with nothing to move on to. |
| skip? | string | The skip button during any other part. |
| nextEpisode? | string | The skip button during credits, with another item in the playlist. |
| ambient? | string | The name of the ambient light row in the settings menu. |
| backToVideo? | string | The label on the mini player's button that scrolls back to the video. |
| screenshot? | string | The name of the row that saves the current frame. |
| screenshotSaved? | string | The message after saving a frame. |
| screenshotFailed? | string | The message when a frame can't be saved. |
| loop? | string | The name of the loop row and its submenu in the settings menu. |
| loopVideo? | string | The choice in the loop menu that repeats the whole video. |
| loopStart? | string | The row in the loop menu that starts a section at the current position. |
| loopEnd? | string | The row in the loop menu that ends a section at the current position. |
| shortcuts? | string | The title of the shortcuts list, and its row in the settings menu. |
| shortcutPlayPause? | string | The name of the play and pause shortcut. |
| shortcutVolumeUp? | string | The name of the shortcut that raises the volume. |
| shortcutVolumeDown? | string | The name of the shortcut that lowers the volume. |
| shortcutMute? | string | The name of the mute shortcut. |
| shortcutFaster? | string | The name of the shortcut that speeds playback up. |
| shortcutSlower? | string | The name of the shortcut that slows playback down. |
| shortcutStart? | string | The name of the shortcut to the start. |
| shortcutEnd? | string | The name of the shortcut to the end. |
| shortcutJump? | string | The name of the number keys, which jump through the video. |
| stats? | string | The title of the stats readout, and its row in the settings menu. |
| statsVideo? | string | The stats row for the picture's size. |
| statsViewport? | string | The stats row for the player's size on the page. |
| statsFrames? | string | The stats row for dropped frames. |
| statsBuffer? | string | The stats row for how much is downloaded ahead. |
| statsEngine? | string | The stats row for the active provider. |
| statsLatency? | string | The stats row for the distance from the live edge. |
| copy? | string | The label on the stats readout's copy button. |
| copied? | string | The label on that button just after copying. |
| share? | string | The label on the share button. |
| linkCopied? | string | The message after copying a link. |
| linkFailed? | string | The message when a link can't be copied. |
| fill? | string | The label on the fit button while the whole picture shows. |
| fitWhole? | string | The label on the fit button while the picture fills the frame. |
| transcriptResume? | string | The 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:
"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:
"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
rtlautomatically:ar,dv,fa,he,ks,ps,sd,ug,ur, andyi. Only the language part of the tag counts, soar-EGisrtlandpt-BRisltr. - 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
| Option | Type | Description |
|---|---|---|
| locale | string | A BCP 47 tag, such as "ar" or "pt-BR". |
| strings? | Strings | Strings 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) => …).
| Field | Type | Description |
|---|---|---|
| locale | string | The current language, written to Root as lang. |
| strings | Record<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).
| Command | Type | Description |
|---|---|---|
| setLocale | (locale: string, strings?: Strings, dir?: "ltr" | "rtl") => void | Switches language while playing. |