fast-react-i18n
Version:
Minimalist i18n library for React and Next.js
51 lines (47 loc) • 1.79 kB
TypeScript
import * as react_jsx_runtime from 'react/jsx-runtime';
import React from 'react';
interface I18nProviderProps {
initialLocale?: string;
fallbackLocale?: string;
translationsPath: string;
persist?: boolean;
children: React.ReactNode;
}
declare const I18nProvider: ({ initialLocale, fallbackLocale, translationsPath, persist, children, }: I18nProviderProps) => react_jsx_runtime.JSX.Element;
/**
* Clears all cached translation data from localStorage.
* It removes all keys that start with "i18n_".
*/
declare const clearTranslationsCache: () => void;
/**
* Hook to retrieve the current translation context.
*
* @returns {Record<string, any>} An object containing the current translations.
*/
declare const useTranslation: () => Record<string, any>;
/**
* Detects the user's preferred locale.
*
* Detection order:
* 1. URL query parameter "lang"
* 2. Cookie "lang"
* 3. Browser navigator.language
* 4. Fallback to "en"
*
* @returns {string} The detected locale (e.g., "en", "es").
*/
declare const detectUserLocale: () => string;
/**
* Hook to reload and update translations for the current locale.
*
* @returns {(path: string, fallbackLocale?: string) => Promise<void>} A function to reload translations.
*/
declare const useForceReloadTranslations: () => (path: string, fallbackLocale?: string) => Promise<void>;
/**
* Loads a list of available locales from the provided path.
*
* @param {string} path - The base path to the locales directory.
* @returns {Promise<string[]>} A promise resolving to an array of available locale codes.
*/
declare const loadAvailableLocales: (path: string) => Promise<string[]>;
export { I18nProvider, clearTranslationsCache, detectUserLocale, loadAvailableLocales, useForceReloadTranslations, useTranslation };