@arckit/i18n
v1.1.1
Published
Internationalization with i18next, language detection, and React provider support
Maintainers
Readme
@arckit/i18n
Internationalization with i18next, language detection, and React provider support.
📑 Table of Contents
- 🪧 About
- 📦 Installation
- 🚀 Usage
- 📖 API
- 🤗 Contributing
- 📝 License
Framework-agnostic i18n library built on i18next with pluggable language detectors, resource loaders, and React provider support. Includes a Next.js subpath for server-side language detection and metadata translation.
pnpm add @arckit/i18nCore — language detection
import { detectLng } from '@arckit/i18n';
import { fromCookie, fromHeader } from '@arckit/i18n/detectors';
const lng = await detectLng(request, {
detectors: [fromCookie({ cookieName: 'locale', supportedLngs }), fromHeader({ supportedLngs })],
fallbackLng: 'en-US'
});Client — React provider
import { I18nProvider } from '@arckit/i18n/client';
<I18nProvider locale={locale} namespaces={namespaces} resources={resources}>
{children}
</I18nProvider>Core (@arckit/i18n)
| Export | Description |
|--------|-------------|
| detectLng(request, options) | Detect language from request using pluggable detectors |
| RESOURCE_LOADER | Injection key for the resource loader function |
| TRANSLATION | Injection key for the translation function |
| withTranslation(Component) | HOC that injects the t function as prop |
Client (@arckit/i18n/client)
| Export | Description |
|--------|-------------|
| I18nProvider | React provider for client-side i18n context |
Detectors (@arckit/i18n/detectors)
| Export | Description |
|--------|-------------|
| fromCookie(options) | Detect language from a cookie |
| fromHeader(options) | Detect language from Accept-Language header |
| fromUrl(options) | Detect language from URL path |
See CONTRIBUTING.md for details.
MIT © Marc Gavanier
