next-i18next
Version:
The easiest way to translate your NextJs apps.
108 lines (106 loc) • 3.73 kB
text/typescript
import React from "react";
import { FlatNamespace, KeyPrefix, Resource } from "i18next";
import { FallbackNs, Trans, UseTranslationOptions, UseTranslationResponse } from "react-i18next";
import * as react_jsx_runtime0 from "react/jsx-runtime";
//#region src/appRouter/client.d.ts
type $Tuple<T> = readonly [T?, ...T[]];
interface I18nProviderProps {
children: React.ReactNode;
/** Current language (detected on the server, passed from layout) */
language: string;
/** Server-loaded resources to hydrate the client instance */
resources?: Resource;
/** All supported languages */
supportedLngs?: string[];
/** Default namespace */
defaultNS?: string;
/** Fallback language */
fallbackLng?: string | string[] | Record<string, string[]>;
/** Path to locale files (for lazy-loading additional namespaces on the client) */
localePath?: string;
/** Locale file structure pattern */
localeStructure?: string;
/** Locale file extension */
localeExtension?: string;
/** Extra i18next plugins (e.g., i18next-http-backend, i18next-locize-backend) */
use?: any[];
/** Additional i18next init options */
i18nextOptions?: Record<string, any>;
}
/**
* Client-side i18next provider for App Router.
* Creates an i18next instance hydrated with server-loaded resources,
* with fallback dynamic loading for additional namespaces.
*
* Supports custom backends via the `use` prop — pass i18next-http-backend,
* i18next-locize-backend, or i18next-chained-backend to load translations
* from external sources.
*
* @example
* ```tsx
* // In app/[lng]/layout.tsx (Server Component)
* import { I18nProvider } from 'next-i18next/client'
* import { getT, getResources } from 'next-i18next/server'
*
* export default async function Layout({ children, params }) {
* const { lng } = await params
* const { i18n } = await getT()
* const resources = getResources(i18n, ['common'])
* return (
* <I18nProvider language={lng} resources={resources}>
* {children}
* </I18nProvider>
* )
* }
* ```
*/
declare function I18nProvider({
children,
language,
resources,
supportedLngs,
defaultNS,
fallbackLng,
localePath,
localeStructure,
localeExtension,
use,
i18nextOptions
}: I18nProviderProps): react_jsx_runtime0.JSX.Element;
/**
* Translation hook for Client Components in App Router.
* Works in both locale-in-path and no-locale-path modes:
* - Locale-in-path: reads language from URL params (`[lng]` or `[locale]`) and syncs
* - No-locale-path: uses the language set by I18nProvider (from server detection)
*
* @example
* ```tsx
* 'use client'
* import { useT } from 'next-i18next/client'
*
* export default function Counter() {
* const { t } = useT('home')
* return <p>{t('greeting')}</p>
* }
* ```
*/
declare function useT<Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined = undefined, KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined>(ns?: Ns, options?: UseTranslationOptions<KPrefix>): UseTranslationResponse<FallbackNs<Ns>, KPrefix>;
/**
* Hook for changing the language without URL navigation (no-locale-path mode).
* Updates cookie + i18next instance + triggers server re-render via router.refresh().
*
* @example
* ```tsx
* 'use client'
* import { useChangeLanguage } from 'next-i18next/client'
*
* export default function LanguageSwitcher() {
* const changeLanguage = useChangeLanguage()
* return <button onClick={() => changeLanguage('de')}>Deutsch</button>
* }
* ```
*/
declare function useChangeLanguage(cookieName?: string): (newLng: string) => Promise<void>;
//#endregion
export { I18nProvider, I18nProviderProps, Trans, useChangeLanguage, useT };
//# sourceMappingURL=client.d.mts.map