@whiskeyjack-net/i18n
v0.1.1
Published
Shared react-i18next bootstrap for Whiskeyjack apps: one createI18n() with language detection, en fallback, and <html lang/dir> (RTL) sync.
Maintainers
Readme
@whiskeyjack-net/i18n
The shared react-i18next bootstrap used by every Whiskeyjack app. One
createI18n() instead of copy-pasting the i18next init, so language detection,
the React binding, the en fallback, and <html lang>/dir (RTL) sync are
identical everywhere.
This README documents the published artifact (@whiskeyjack-net/i18n, staged
via npm run build:package). Inside the monorepo the workspace source export is
@whiskeyjack/i18n.
Install
npm install @whiskeyjack-net/i18nRequires react 18+ (peer). Ships i18next, react-i18next, and
i18next-browser-languagedetector as dependencies.
Use
// src/i18n/index.ts
import { createI18n } from '@whiskeyjack-net/i18n'
import en from './locales/en.json'
import ar from './locales/ar.json'
export default createI18n({ en, ar })// main.tsx
import './i18n'Components use useTranslation() from react-i18next as usual. Each locale is
wrapped in the default translation namespace; coverage varies per app (an
English-only app just passes { en }).
API
createI18n(locales, options?)– configure and return the shared i18next instance.localesmaps a language code to its translation object. OnlanguageChangedit updates<html lang>and<html dir>(RTL for Arabic/Urdu/Farsi/Hebrew).options.fallbackLngdefaults toen.activeLanguage(supported)– the active language normalized to one ofsupported, for binding a language picker to what is actually displayed (including the first-run system-detected language).
License
MIT
