Skip to content
FrameworkStyle

Translator

Typed function that resolves English translation phrases to localized strings

Translator is the callable returned by createTranslator. It turns current English phrases from core controls into localized copy and interpolates {placeholder} tokens when params are required.

Import

import type { Translator } from '@videojs/html/i18n';

Definition

type Translator = <K extends keyof TranslationParams>(
  key: K,
  ...args: TranslationParams[K] extends never ? [] : [params: TranslationParams[K]]
) => string;
  • Plain phrases: t('Play')
  • Parametric phrases: t('Seek forward {seconds} seconds', { seconds: 10 })

Missing phrases in the active map resolve to the source English ('Play') so partial locale packs stay readable.

Create manually

import { createTranslator, getI18nTranslations } from '@videojs/html/i18n';

const t = createTranslator(getI18nTranslations('pt-BR'), 'pt-BR');
t('Pause');

Control components resolve phrases from core getLabel() through their framework adapters. You rarely call t() directly unless building custom UI.