패키지 목록
@hua-labs/i18n-loaders
v1.1.0-alpha.4
Loader
Cache
프로덕션 환경을 위한 번역 로더, 캐싱, 프리로드 헬퍼. API 기반 동적 로딩 지원.
$npm install @hua-labs/i18n-loaders
주요 기능
API 로더
REST API에서 번역을 동적으로 로드
스마트 캐싱
TTL 기반 캐시, 중복 요청 방지
자동 재시도
지수 백오프로 네트워크 오류 복구
프리로드
네임스페이스 미리 로드로 성능 최적화
빠른 시작
1. API 로더 생성
typescript
import { createApiTranslationLoader } from '@hua-labs/i18n-loaders';
const { loader, invalidate, clear } = createApiTranslationLoader({
translationApiPath: '/api/translations',
cacheTtlMs: 5 * 60 * 1000, // 5분
retryCount: 3,
retryDelay: 1000,
autoInvalidateInDev: true,
});
// i18n 설정에서 사용
const config = {
loadTranslations: loader,
// ...
};2. 네임스페이스 프리로드
typescript
import { preloadNamespaces } from '@hua-labs/i18n-loaders';
// 앱 시작 시 필요한 네임스페이스 미리 로드
await preloadNamespaces({
loader,
languages: ['ko', 'en'],
namespaces: ['common', 'navigation'],
});3. 캐시 관리
typescript
// 특정 언어/네임스페이스 캐시 무효화
invalidate('ko', 'common');
// 특정 언어의 모든 캐시 무효화
invalidate('ko');
// 전체 캐시 클리어
clear();API Reference
createApiTranslationLoader(options)
| 옵션 | Type | Default |
|---|---|---|
| translationApiPath | string | /api/translations |
| cacheTtlMs | number | 300000 (5min) |
| retryCount | number | 0 |
| retryDelay | number | 1000 |
| disableCache | boolean | false |
| autoInvalidateInDev | boolean | true (dev) |
Exports
createApiTranslationLoaderAPI 기반 번역 로더 팩토리
preloadNamespaces네임스페이스 프리로드 함수
warmFallbackLanguages폴백 언어 워밍업 함수
withDefaultTranslations기본 번역 래퍼