react-i18next
- Version 15.4.0
- Published
- 330 kB
- 2 dependencies
- MIT license
Install
npm i react-i18next
yarn add react-i18next
pnpm add react-i18next
Overview
Internationalization for react done right. Using the i18next i18n ecosystem.
Index
Variables
Functions
Interfaces
Type Aliases
Variables
variable I18nContext
const I18nContext: React.Context<{ i18n: i18n }>;
variable I18nextProvider
const I18nextProvider: React.FunctionComponent<I18nextProviderProps>;
variable initReactI18next
const initReactI18next: ThirdPartyModule;
variable TransWithoutContext
const TransWithoutContext: < Key extends ParseKeys<Ns, TOpt, KPrefix>, Ns extends Namespace = TypeOptions, KPrefix = undefined, TContext extends string = undefined, TOpt extends unknown = { context: TContext }, E = React.HTMLProps<HTMLDivElement>>( props: TransProps<Key, Ns, KPrefix, TContext, TOpt, E>) => React.ReactElement;
Functions
function composeInitialProps
composeInitialProps: (ForComponent: any) => (ctx: unknown) => Promise<any>;
function getDefaults
getDefaults: () => ReactOptions;
function getI18n
getI18n: () => i18n;
function getInitialProps
getInitialProps: () => { initialI18nStore: { [ns: string]: {} }; initialLanguage: string;};
function setDefaults
setDefaults: (options: ReactOptions) => void;
function setI18n
setI18n: (instance: i18n) => void;
function Trans
Trans: < Key extends ParseKeys<Ns, TOpt, KPrefix>, Ns extends Namespace = TypeOptions, KPrefix = undefined, TContext extends string = undefined, TOpt extends unknown = { context: TContext }, E = React.HTMLProps<HTMLDivElement>>( props: TransProps<Key, Ns, KPrefix, TContext, TOpt, E>) => React.ReactElement;
function Translation
Translation: < Ns extends unknown = undefined, KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined>( props: TranslationProps<Ns, KPrefix>) => any;
function useSSR
useSSR: (initialI18nStore: Resource, initialLanguage: string) => void;
function useTranslation
useTranslation: < Ns extends unknown = undefined, KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined>( ns?: Ns, options?: UseTranslationOptions<KPrefix>) => UseTranslationResponse<FallbackNs<Ns>, KPrefix>;
function withSSR
withSSR: () => <Props>(WrappedComponent: React.ComponentType<Props>) => { ({ initialI18nStore, initialLanguage, ...rest }: { initialI18nStore: Resource; initialLanguage: string; } & Props): React.FunctionComponentElement<Props>; getInitialProps: (ctx: unknown) => Promise<any>;};
function withTranslation
withTranslation: < Ns extends unknown = undefined, KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined>( ns?: Ns, options?: { withRef?: boolean; keyPrefix?: KPrefix }) => < C extends React.ComponentType<any>, ResolvedProps = React.JSX.LibraryManagedAttributes< C, $Subtract<React.ComponentProps<C>, WithTranslationProps> >>( component: C) => React.ComponentType< Omit<ResolvedProps, keyof WithTranslation<Ns, undefined>> & WithTranslationProps>;
Interfaces
interface I18nextProviderProps
interface I18nextProviderProps {}
interface ReportNamespaces
interface ReportNamespaces {}
method addUsedNamespaces
addUsedNamespaces: (namespaces: Namespace) => void;
method getUsedNamespaces
getUsedNamespaces: () => string[];
interface TranslationProps
interface TranslationProps< Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined = undefined, KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined> {}
property children
children: ( t: TFunction<FallbackNs<Ns>, KPrefix>, options: { i18n: i18n; lng: string; }, ready: boolean) => React.ReactNode;
property i18n
i18n?: i18n;
property keyPrefix
keyPrefix?: KPrefix;
property ns
ns?: Ns;
property nsMode
nsMode?: 'fallback' | 'default';
property useSuspense
useSuspense?: boolean;
interface UseTranslationOptions
interface UseTranslationOptions<KPrefix> {}
interface WithTranslation
interface WithTranslation< Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined = undefined, KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined> {}
interface WithTranslationProps
interface WithTranslationProps {}
property i18n
i18n?: i18n;
property useSuspense
useSuspense?: boolean;
Type Aliases
type ErrorArgs
type ErrorArgs = readonly [string, ErrorMeta | undefined, ...any[]];
Use to type the logger arguments
Example 1
import type { ErrorArgs } from 'react-i18next';const logger = {// ....warn: function (...args: ErrorArgs) {if (args[1]?.code === 'TRANS_INVALID_OBJ') {const [msg, { i18nKey, ...rest }] = args;return log(i18nKey, msg, rest);}log(...args);}}i18n.use(logger).use(i18nReactPlugin).init({...});
type ErrorCode
type ErrorCode = | 'NO_I18NEXT_INSTANCE' | 'NO_LANGUAGES' | 'DEPRECATED_OPTION' | 'TRANS_NULL_VALUE' | 'TRANS_INVALID_OBJ' | 'TRANS_INVALID_VAR' | 'TRANS_INVALID_COMPONENTS';
type FallbackNs
type FallbackNs<Ns> = Ns extends undefined ? _DefaultNamespace : Ns extends Namespace ? Ns : _DefaultNamespace;
type TransProps
type TransProps< Key extends ParseKeys<Ns, TOpt, KPrefix>, Ns extends Namespace = _DefaultNamespace, KPrefix = undefined, TContext extends string | undefined = undefined, TOpt extends TOptions & { context?: TContext } = { context: TContext }, E = React.HTMLProps<HTMLDivElement>> = E & { children?: TransChild | readonly TransChild[]; components?: | readonly React.ReactElement[] | { readonly [tagName: string]: React.ReactElement }; count?: number; context?: TContext; defaults?: string; i18n?: i18n; i18nKey?: Key | Key[]; ns?: Ns; parent?: string | React.ComponentType<any> | null; // used in React.createElement if not null tOptions?: TOpt; values?: {}; shouldUnescape?: boolean; t?: TFunction<Ns, KPrefix>;};
type UseTranslationResponse
type UseTranslationResponse<Ns extends Namespace, KPrefix> = [ t: TFunction<Ns, KPrefix>, i18n: i18n, ready: boolean] & { t: TFunction<Ns, KPrefix>; i18n: i18n; ready: boolean;};
Package Files (3)
Dependencies (2)
Dev Dependencies (51)
- @babel/cli
- @babel/core
- @babel/eslint-parser
- @babel/plugin-proposal-async-generator-functions
- @babel/plugin-proposal-object-rest-spread
- @babel/plugin-transform-modules-commonjs
- @babel/plugin-transform-runtime
- @babel/polyfill
- @babel/preset-env
- @babel/preset-react
- @babel/register
- @rollup/plugin-babel
- @rollup/plugin-commonjs
- @rollup/plugin-node-resolve
- @rollup/plugin-replace
- @rollup/plugin-terser
- @testing-library/dom
- @testing-library/jest-dom
- @testing-library/react
- @types/jest
- @types/react
- @vitest/coverage-v8
- all-contributors-cli
- babel-core
- babel-plugin-macros
- babel-plugin-tester
- coveralls
- cpy-cli
- cross-env
- eslint
- eslint-config-airbnb
- eslint-config-prettier
- eslint-plugin-import
- eslint-plugin-jest-dom
- eslint-plugin-jsx-a11y
- eslint-plugin-react
- eslint-plugin-testing-library
- happy-dom
- husky
- i18next
- lint-staged
- mkdirp
- prettier
- react
- react-dom
- react-test-renderer
- rimraf
- rollup
- typescript
- vitest
- yargs
Peer Dependencies (2)
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/react-i18next
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/react-i18next)
- HTML<a href="https://www.jsdocs.io/package/react-i18next"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2457 ms. - Missing or incorrect documentation? Open an issue for this package.