Skip to content
FrameworkStyle

createI18n

Factory that creates framework i18n helpers with custom loading options

Import

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

createI18n returns an I18nProvider, useTranslator, and useLocale wired to the shared React i18n context used by the stock skins and controls. Use it when you need options such as a custom locale loader. Most apps use the default exports from @videojs/react/i18n.

import { createI18n } from '@videojs/react/i18n';

const loaders = {
  ja: () => import('@videojs/react/i18n/locales/ja'),
};

const { I18nProvider, useTranslator } = createI18n({
  loader: async (tag) => {
    const load = loaders[tag as keyof typeof loaders];
    return load ? (await load()).default : undefined;
  },
});

function App() {
  return (
    <I18nProvider locale="ja">
      <Controls />
    </I18nProvider>
  );
}

API Reference

Parameters

ParameterTypeDefaultDetails
optionsobject

Return Value

PropertyTypeDetails
I18nContextContext<I18nContextValue | null>
I18nProviderfunction
useTranslatortypeof useTranslator
useLocaletypeof useLocale