@hua-labs/i18n-loaders
v2.2.1
Published
Production-ready loaders, caching, and preloading helpers for @hua-labs/i18n-core.
Maintainers
Readme
@hua-labs/i18n-loaders
Production-ready translation loaders with built-in TTL caching, duplicate request prevention, and namespace preloading. Designed to work seamlessly with @hua-labs/i18n-core. Supports both server and client environments.
Features
- API loader — createApiTranslationLoader with configurable endpoints
- TTL caching — Time-based cache with global cache support
- Duplicate prevention — Deduplicates concurrent requests for the same resource
- Preloading — Warm up namespaces and fallback languages at startup
- React Native — Works in Expo and bare RN projects
- Default merging — Merge API translations with bundled defaults
Installation
pnpm add @hua-labs/i18n-loadersPeer dependencies: react >=19.0.0
Quick Start
import { createCoreI18n } from '@hua-labs/i18n-core';
import { createApiTranslationLoader, preloadNamespaces } from '@hua-labs/i18n-loaders';
const loader = createApiTranslationLoader({
translationApiPath: '/api/translations',
cacheTtlMs: 60_000,
retryCount: 2,
});
// Preload at startup
preloadNamespaces('ko', ['common', 'dashboard'], loader);
// Use with i18n-core
const I18nProvider = createCoreI18n({
defaultLanguage: 'ko',
translationLoader: 'custom',
loadTranslations: loader,
});
API
| Export | Type | Description |
|--------|------|-------------|
| createApiTranslationLoader | function | Create API-based loader with caching and retry |
| preloadNamespaces | function | Preload translation namespaces |
| warmFallbackLanguages | function | Warm up fallback language caches |
| withDefaultTranslations | function | Merge API results with bundled defaults |
| ApiLoaderOptions | type | |
| CacheInvalidation | type | |
| DefaultTranslations | type | |
| PreloadOptions | type | |
| TranslationLoader | type | |
| TranslationRecord | type | |
Documentation
Related Packages
License
MIT — HUA Labs
