@haykal/i18n-backend
v1.0.0
Published
> Internationalization module with locale management, translation CRUD, namespaced keys, import/export, and missing key detection.
Readme
@haykal/i18n-backend
Internationalization module with locale management, translation CRUD, namespaced keys, import/export, and missing key detection.
Installation
pnpm add @haykal/i18n-backendConfiguration
forRoot() Options
import { I18nModule } from '@haykal/i18n-backend';
@Module({
imports: [
I18nModule.forRoot({
// configuration options
}),
],
})
export class AppModule {}Key Exports
| Export | Type | Description |
| ------------------------ | ------------- | ----------------------------------------------- |
| I18nModule | NestJS Module | Main module with forRoot() / forRootAsync() |
| TranslationEntity | Entity | Translation entries |
| I18N_ENTITIES | Array | Entities for migration discovery |
| TranslationsService | Service | Translation CRUD and management |
| TranslationsRepository | Repository | Data access layer |
API Endpoints
Base path: /api/i18n and /api/i18n-admin.
Public (i18n)
| Method | Path | Auth | Description |
| ------ | ------------------------------- | ------ | -------------------------------------- |
| GET | /i18n/locales | Public | List available locales |
| GET | /i18n/translations | Public | Get translations for a locale |
| GET | /i18n/translations/:namespace | Public | Get translations by locale + namespace |
Admin (i18n-admin)
| Method | Path | Auth | Description |
| -------- | ---------------------------------- | ---- | ----------------------------- |
| POST | /i18n-admin/translations | JWT | Create a translation entry |
| PATCH | /i18n-admin/translations/:id | JWT | Update a translation |
| DELETE | /i18n-admin/translations/:id | JWT | Delete a translation |
| GET | /i18n-admin/translations/missing | JWT | Find missing translation keys |
| GET | /i18n-admin/translations/export | JWT | Export translations |
| POST | /i18n-admin/translations/import | JWT | Import translations |
Usage Examples
Using TranslationsService
import { TranslationsService } from '@haykal/i18n-backend';
@Injectable()
export class MyService {
constructor(private readonly i18n: TranslationsService) {}
async getGreeting(locale: string) {
const translations = await this.i18n.getTranslations(locale, 'common');
return translations['greeting'];
}
}Related Packages
@haykal/i18n-client— React Query hooks for i18n@haykal/core-backend— Base infrastructure
Further Reading
- API Reference — Full endpoint listing
- Backend Style Guide — Coding conventions
