Skip to content

Referencei18n

translateText

Translate a text descriptor, or fall back to its English default

Import

import { translateText } from "@videojs/react/i18n";

translateText translates a text descriptor with a translator from createTranslator. Without one, it fills the descriptor’s English default with the params. A plain string is returned as is, so a label can be either.

import { createTranslator, getI18nTranslations, translateText } from '@videojs/react/i18n';
import { forwardText } from '@videojs/react/i18n/text/seek';

translateText(forwardText, { seconds: 10 }); // 'Seek forward 10 seconds'

const t = createTranslator(getI18nTranslations('fr'), 'fr');
translateText(forwardText, t, { seconds: 10 });

API Reference

Overload 1

translateText(text, params?): string

Translate a text descriptor with a translator, or interpolate its English default without one. A plain string is returned as is.

Parameters

ParameterTypeDefaultDetails
text*{ key: string; text: string } | string—
paramsRecord<string, string | number>—

Return Value

string

Overload 2

translateText(text, translator, params?): string

Parameters

ParameterTypeDefaultDetails
text*{ key: string; text: string } | string—
translator*object—
paramsRecord<string, string | number>—

Return Value

string