Files
v10/dist/dev/i18n/create-i18n.d.ts

61 lines
2.6 KiB
TypeScript

import { I18nContextValue, useLocale, useTranslator } from "./context.js";
import { FlatTranslations, Locale, Translations } from "@videojs/core/i18n";
import { Context, ReactNode, RefObject } from "react";
//#region src/i18n/create-i18n.d.ts
interface CreateI18nOptions {
/** Override lazy loading of shipped locale packs (tests or custom loaders). */
loader?: (tag: string) => Promise<Partial<FlatTranslations> | undefined>;
}
interface I18nProviderProps {
/**
* Forces the active locale. Omit to inherit the nearest non-empty `lang` by walking DOM
* ancestors from {@link langRootRef} when set, otherwise from `document.documentElement`
* (typically `<html lang>`). Updates when any `lang` attribute changes anywhere under `<html>`,
* or when subtree moves alter which ancestor supplies `lang`. For SSR, pass `locale` explicitly.
*/
locale?: Locale;
/**
* Element whose ancestor chain is searched for a non-empty `lang` when {@link locale} is
* omitted—for example a ref to your player shell `HTMLElement`.
*/
langRootRef?: RefObject<Element | null>;
/**
* Per-locale string overrides merged on top of the global registry and any lazy built-in
* packs for {@link locale}. Applies to translated
* `aria-label` values and tooltip copy for skin controls wired through `useTranslator`.
*
* @example
* ```tsx
* <I18nProvider locale="ja" translations={{ buttons: { play: '再生', pause: '一時停止' } }}>
* <VideoSkin />
* </I18nProvider>
* ```
*/
translations?: Partial<Translations>;
children: ReactNode;
/** Fires when the resolved locale changes (caption selection hooks may use this later). */
onActiveLocaleChange?: (locale: Locale) => void;
}
interface CreateI18nResult {
I18nContext: Context<I18nContextValue | null>;
I18nProvider: (props: I18nProviderProps) => ReactNode;
useTranslator: typeof useTranslator;
useLocale: typeof useLocale;
}
/**
* Creates an i18n provider and hooks for the shared React i18n context.
*
* @param options - Optional hooks such as custom built-in locale loading.
* @public
*/
declare function createI18n(options?: CreateI18nOptions): CreateI18nResult;
/**
* Resolves locale and supplies a typed translator to descendants. Mount this explicitly for
* translated controls, forced locales, SSR copy, or locale-aware player roots.
*
* @public
*/
declare const I18nProvider: (props: I18nProviderProps) => ReactNode;
//#endregion
export { CreateI18nOptions, CreateI18nResult, type I18nContextValue, I18nProvider, I18nProviderProps, createI18n };
//# sourceMappingURL=create-i18n.d.ts.map