패키지 목록
@hua-labs/i18n-loaders
v1.1.0-alpha.4
Loader
Cache
외부 API에서 번역 데이터를 로드하는 비동기 로더. 스마트 캐싱, 자동 재시도, 네임스페이스 프리로드를 지원합니다.
$npm install @hua-labs/i18n-loaders
주요 기능
API 로더
외부 API에서 번역 데이터를 로드합니다.
스마트 캐싱
불필요한 요청을 줄이는 스마트 캐싱을 지원합니다.
자동 재시도
로딩 실패 시 자동으로 재시도합니다.
프리로드
필요한 번역을 미리 로드하여 성능을 향상시킵니다.
빠른 시작
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기본 번역 데이터 설정