ams-polyglot
v0.1.9
Published
Internationalization module for Moduix React applications using react-i18next.
Maintainers
Readme
Moduix Polyglot Module
A flexible internationalization (i18n) module for React applications, built on top of react-i18next.
Features
- Centralized configuration for supported locales, loading, persistence, and reporting.
- Integration with
i18next-http-backendfor loading translations over HTTP. - Integration with
i18next-browser-languagedetectorfor automatic language detection. - Configurable persistence of the selected language (localStorage, sessionStorage, cookie).
- Optional reporting of missing translation keys to a specified endpoint.
- Provides a
usePolyglothook combiningreact-i18next'stfunction with locale context. - Includes a customizable
PolyglotModalcomponent for language selection.
Installation
This module relies on several peer dependencies. Ensure you have them installed in your project:
npm install react react-dom i18next react-i18next i18next-http-backend i18next-browser-languagedetector
# or
yarn add react react-dom i18next react-i18next i18next-http-backend i18next-browser-languagedetectorUsage
- Configure: Create a configuration object based on
PolyglotConfig. - Provide: Wrap your application with the
PolyglotProviderand pass the configuration. Ensure a<React.Suspense>boundary exists above the provider. - Translate: Use the
usePolyglothook in your components to access thetfunction and locale information.
For detailed instructions and examples, see Usage.md.
Components
PolyglotProvider: Context provider for i18n configuration and state.PolyglotModal: UI component for language selection (optional).
Hooks
usePolyglot: Accesses thetfunction, currentlocale,setLocalefunction, configuration, and other i18n context.
