adelson-localization
v1.1.1
Published
๐ Dynamic React localization hook with live translation updates - An alternative to i18next
Maintainers
Readme
๐ Adelson Localization
A lightweight, dynamic React localization hook with live translation updates without redeployment.
๐ What's New in v1.1.0
- ๐ Multiple Resource Files - Split translations across multiple files for better organization
- ๐ง Utility Functions - Export
deepMergeandstrictDeepMergefor custom use cases - โ 64 Tests - Comprehensive test coverage for reliability
- ๐ Zero Dependencies - Lightweight and secure (dev dependencies only)
๐ Why Adelson Localization?
| Feature | Adelson Localization | i18next |
|---------|---------------------|---------|
| Live Updates | โ
Update translations on server, users get updates on next load | โ ๏ธ Requires rebuild |
| Dynamic Formatting | โ
Mix indexed {{}} and named {{name}} placeholders | โ
Named only |
| Plural Rules | โ
Built-in (7 languages) | โ
Via plugins |
| TypeScript Generics | โ
ln<T>() for any type | โ ๏ธ Limited |
| Bundle Size | ๐ชถ ~5KB minified | ๐ฆ Varies with plugins |
| Setup | ๐ Single hook, zero config | ๐ง Provider setup required |
๐ฅ Key Advantage: Update Translations Without Redeployment
Update your translation files on the server, and users get the latest content on next page load or language change without app redeployment.
๐ See detailed comparison with i18next โ
๐ฎ Live Demo
Try adelson-localization instantly in your browser:
No installation required! Fork, modify, and test in seconds.
๐บ See all demos and examples โ
๐ฆ Installation
npm install adelson-localization
# or
yarn add adelson-localization๐ฏ Quick Start
1. Create translation files
/public/locales/en/translation.json{
"app": {
"title": "My Application",
"welcome": "Welcome {{}}!"
},
"messages": {
"notification": {
"singular": "You have {{}} new message",
"plural": "You have {{}} new messages"
}
}
}2. Use the hook in your component
import { useLanguage } from 'adelson-localization';
function App() {
const { ln, lnPlural, language, setLanguage } = useLanguage({ lang: "en" });
return (
<div>
<h1>{ln("app.title")}</h1>
<p>{ln("app.welcome", "John")}</p>
<p>{lnPlural("messages.notification", 5)}</p>
<button onClick={() => setLanguage({ key: "fr" })}>
Switch to French
</button>
</div>
);
}๐ Documentation
Core Features
- ๐ API Reference - Complete API documentation
- ๐ก Usage Examples - Placeholders, plurals, TypeScript generics
- ๐ Plural Rules - Language-specific plural rules
Advanced Features (v1.1.0+)
- ๐จ Advanced Features - HMR, CDN, multiple files, multiple languages
- ๐ง Utility Functions -
deepMergeandstrictDeepMerge - ๐ญ Mock Data Guide - Type-safe mock data in translations
Migration & Best Practices
- ๐ Best Practices - Recommendations and tips
- ๐ Migration from i18next - Step-by-step migration guide
โก Key Features
Multiple Resource Files (v1.1.0+)
Split translations across multiple files for better organization:
const { ln } = useLanguage({
lang: "en",
resourceFiles: ["common.json", "auth.json", "dashboard.json"]
});
ln("common.buttons.save") // from common.json
ln("auth.login.title") // from auth.json
ln("dashboard.stats.users") // from dashboard.json๐ Learn more about multiple resource files โ
Hot Module Replacement (HMR)
Auto-reload translations during development:
const { ln } = useLanguage({
lang: "en",
enableHMR: true // โก Translations update automatically
});TypeScript Generics
Type-safe data retrieval:
const maxItems = ln<number>("config.maxItems");
const features = ln<string[]>("config.features");
const settings = ln<AppSettings>("app.settings");๐ก See TypeScript examples โ
Plural Support
Built-in plural rules for 7 languages (EN, FR, ES, DE, IT, PT, NL):
lnPlural("messages.notification", 1); // "You have 1 new message"
lnPlural("messages.notification", 5); // "You have 5 new messages"๐ Learn about plural rules โ
๐ง Utility Functions (v1.1.0+)
Export utility functions for your own use:
import { deepMerge, strictDeepMerge } from 'adelson-localization';
// Deep merge objects
const config = deepMerge(defaults, userPrefs, overrides);
// Strict merge (only updates existing keys)
strictDeepMerge(schema, updates);๐จ See utility functions documentation โ
๐ API Quick Reference
interface UseLanguageConfig {
lang?: string; // Initial language (default: "en")
translationsUrl?: string; // Base URL (default: "/locales")
managedLanguages?: string[]; // Supported languages (default: ["en", "fr", "es"])
enableHMR?: boolean; // Enable HMR in dev (default: false)
resourceFiles?: string[]; // ๐ Files to load (default: ["translation.json"])
}
const {
ln, // Localization function
lnPlural, // Plural localization
language, // Current language
setLanguage, // Change language
resource, // Raw translation data
loadingResource // Loading state
} = useLanguage(config);๐ Comparison with i18next
| Scenario | Choose Adelson Localization | Choose i18next | |----------|----------------------------|----------------| | Simple setup needed | โ | โ | | Live updates without rebuild | โ | โ | | Lightweight bundle | โ | โ | | Complex namespaces | โ | โ | | Extensive plugins | โ | โ | | Backend integration | โ ๏ธ Manual | โ Built-in |
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
๐ License
MIT ยฉ Jean Junior Adelson
๐ Acknowledgments
Created by Jean Junior Adelson as a modern, lightweight alternative to existing i18n solutions.
๐ Support
- ๐ Report Issues
- ๐ฌ Discussions
- ๐ง Email: [email protected]
Made with โค๏ธ by Jean Junior Adelson
