leximind-i18n
v0.2.0
Published
π Next-gen multilingual translation engine for React β smart caching, auto-detection, advanced utilities, and blazing-fast performance
Maintainers
Readme
π§ LexiMind i18n
The Best Multilingual Translation Engine for React
Make your React apps speak every language β with smart caching, advanced utilities, and unmatched performance.
π Documentation β’ π Quick Start β’ π‘ Examples β’ π Report Bug
β¨ Features
β‘ Lightning Fast
Smart caching system for offline support and instant translations.
π Intelligent Detection
Auto-detects language from URL, localStorage, browser, and HTML tags.
πͺΆ Lightweight & Powerful
Small bundle size with enterprise-grade features.
π¨ Advanced Formatting
Built-in date, number, and currency formatting with Intl API.
π Dynamic Loading
Lazy load translations on demand with preloading support.
π― Developer-Friendly
Context Provider, utilities, performance monitoring, and TypeScript ready.
π Production Ready
Translation validation, error handling, and performance insights.
π§ Highly Extensible
Rich utilities for pluralization, gender, markdown, and context.
π Quick Start
Installation
npm install leximind-i18n i18next react-i18nextBasic Usage
import { initLexiMind, useLexiMind } from 'leximind-i18n'
// Initialize once in your app entry point
await initLexiMind({
resources: {
en: { translation: { welcome: 'Welcome', hello: 'Hello, {{name}}!' } },
es: { translation: { welcome: 'Bienvenido', hello: 'Β‘Hola, {{name}}!' } },
fr: { translation: { welcome: 'Bienvenue', hello: 'Bonjour, {{name}}!' } }
},
fallbackLng: 'en'
})
// Use in any component
function App() {
const { language, setLanguage, t } = useLexiMind()
return (
<div>
<h1>{t('welcome')}</h1>
<p>{t('hello', { name: 'World' })}</p>
<button onClick={() => setLanguage('en')}>πΊπΈ English</button>
<button onClick={() => setLanguage('es')}>πͺπΈ EspaΓ±ol</button>
<button onClick={() => setLanguage('fr')}>π«π· FranΓ§ais</button>
</div>
)
}That's it! π Your app is now multilingual.
π Core API
initLexiMind(options)
Initialize the translation engine with advanced caching and detection.
await initLexiMind({
resources: { /* your translations */ },
fallbackLng: 'en',
cache: true, // Enable smart caching (default: true)
cacheVersion: '1.0.0', // Cache version for invalidation
backend: {
loadPath: '/locales/{{lng}}/{{ns}}.json'
},
onLanguageChange: (lng) => {
console.log('Language changed to:', lng)
}
})useLexiMind() Hook
React hook for component-level translations.
const {
language, // Current language code
setLanguage, // Change language function
t, // Translation function
ready, // Initialization status
i18n // i18next instance
} = useLexiMind()LexiMindProvider - Context Provider
Wrap your app for global translation access.
import { LexiMindProvider } from 'leximind-i18n/provider'
<LexiMindProvider onLanguageChange={(lng) => console.log(lng)}>
<App />
</LexiMindProvider>Advanced Utilities
import {
getLanguage, // Get current language
getAllLanguages, // Get all loaded languages
clearCache, // Clear translation cache
formatDate, // Format dates with i18n
formatNumber, // Format numbers
formatCurrency, // Format currency
preloadLanguages, // Preload languages
exists, // Check if key exists
getSafe // Get translation with fallback
} from 'leximind-i18n'
// Format dates
formatDate(new Date(), 'fr') // "15 janv. 2025"
// Format currency
formatCurrency(99.99, 'EUR', 'de') // "99,99 β¬"
// Preload languages for better UX
await preloadLanguages(['es', 'fr', 'de'])Translation Utilities
import {
pluralize, // Smart pluralization
translateWithContext, // Context-aware translations
translateWithGender, // Gender-specific translations
batchTranslate, // Batch multiple translations
validateTranslations, // Validate translation coverage
translateMarkdown // Markdown support
} from 'leximind-i18n/utils'
// Pluralization
pluralize('item', 5) // Uses count for plural forms
// Context-aware (formal/informal)
translateWithContext('greeting', 'formal')
// Validate coverage
const result = validateTranslations(['key1', 'key2'])
console.log(result.coverage) // "100%"Performance Monitoring
import {
getPerformanceInsights,
logPerformanceReport
} from 'leximind-i18n/performance'
// Get metrics
const metrics = getPerformanceInsights()
console.log(metrics.cacheHitRate) // "95.3%"
// Log full report (dev only)
logPerformanceReport()π‘ Advanced Examples
await initLexiMind({
backend: {
loadPath: 'https://cdn.example.com/locales/{{lng}}/{{ns}}.json',
crossDomain: true
},
fallbackLng: 'en'
}){
"item": "{{count}} item",
"item_plural": "{{count}} items",
"item_zero": "No items"
}t('item', { count: 0 }) // "No items"
t('item', { count: 1 }) // "1 item"
t('item', { count: 5 }) // "5 items"{
"user": {
"profile": {
"title": "User Profile",
"edit": "Edit Profile"
}
}
}t('user.profile.title') // "User Profile"const languages = [
{ code: 'en', name: 'English', flag: 'πΊπΈ' },
{ code: 'es', name: 'EspaΓ±ol', flag: 'πͺπΈ' },
{ code: 'fr', name: 'FranΓ§ais', flag: 'π«π·' }
]
function LanguageSwitcher() {
const { language, setLanguage } = useLexiMind()
return (
<select value={language} onChange={(e) => setLanguage(e.target.value)}>
{languages.map(lang => (
<option key={lang.code} value={lang.code}>
{lang.flag} {lang.name}
</option>
))}
</select>
)
}π¦ What's Included
- β Automatic language detection (browser + localStorage)
- β Instant language switching (no page reload)
- β Local and remote translation loading
- β
React hooks API (
useLexiMind) - β
Global translation helper (
t()) - β Nested translation keys
- β
Variable interpolation (
Hello, {{name}}) - β Pluralization support
- β Namespace support
- β Missing key warnings
- β localStorage persistence
- β TypeScript support (coming soon)
π οΈ Built With
LexiMind is a lightweight wrapper around these battle-tested libraries:
- i18next β The core i18n framework
- react-i18next β React bindings
- i18next-browser-languagedetector β Auto language detection
- i18next-http-backend β Load translations from server/CDN
π Documentation
- Full Documentation β Complete guide
- API Reference β All methods and options
- Examples β Real-world use cases
- GitHub Repository β Source code
π€ Contributing
Contributions are welcome! Feel free to:
- π Report bugs
- π‘ Suggest features
- π Improve documentation
- π§ Submit pull requests
π License
MIT Β© Rohan Singh
π¬ Support
- π§ Email: [email protected]
- π Issues
- π¬ Discussions
Made with β€οΈ for the React community
If you find this useful, please β star the repo!
