react-i18next

  • Version 15.6.0
  • Published
  • 332 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

variable FlatNamespace

const FlatNamespace: any;

    variable I18nContext

    const I18nContext: React.Context<{ i18n: i18n }>;

      variable I18nextProvider

      const I18nextProvider: React.FunctionComponent<I18nextProviderProps>;

        variable initReactI18next

        const initReactI18next: ThirdPartyModule;

          variable KeyPrefix

          const KeyPrefix: any;

            variable KPrefix

            const KPrefix: any;

              variable Ns

              const Ns: any;

                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: () => any;

                                      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 {}

                                            property children

                                            children?: React.ReactNode;

                                              property defaultNS

                                              defaultNS?: string | string[];

                                                property i18n

                                                i18n: i18n;

                                                  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> {}

                                                                        property bindI18n

                                                                        bindI18n?: string | false;

                                                                          property i18n

                                                                          i18n?: i18n;

                                                                            property keyPrefix

                                                                            keyPrefix?: KPrefix;

                                                                              property lng

                                                                              lng?: string;

                                                                                property nsMode

                                                                                nsMode?: 'fallback' | 'default';

                                                                                  property useSuspense

                                                                                  useSuspense?: boolean;

                                                                                    interface WithTranslation

                                                                                    interface WithTranslation<
                                                                                    Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined = undefined,
                                                                                    KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined
                                                                                    > {}

                                                                                      property i18n

                                                                                      i18n: i18n;

                                                                                        property t

                                                                                        t: TFunction<FallbackNs<Ns>, KPrefix>;

                                                                                          property tReady

                                                                                          tReady: boolean;

                                                                                            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)

                                                                                                          Peer Dependencies (3)

                                                                                                          Badge

                                                                                                          To add a badge like this onejsDocs.io badgeto 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>