Skip to content

arckit-dev/i18n

Repository files navigation

@arckit/i18n

Internationalization with i18next, language detection, and React provider support.

npm version npm downloads bundle size codecov TypeScript

📑 Table of Contents

🪧 About

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.

📦 Installation

pnpm add @arckit/i18n

🚀 Usage

Core — 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>

📖 API

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

🤗 Contributing

See CONTRIBUTING.md for details.

📝 License

MIT © Marc Gavanier

About

nternationalization with i18next, language detection, and React provider support

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors