Internationalised errors
Producers across the library throw i18n codes, not sentences:
ts
import { apiError } from '@sdcorejs/nestjs/core';
throw new BadRequestException(apiError('core.validation.failed', 'Validation failed', { issues }));@sdcorejs/nestjs/i18n closes the loop end-to-end:
SdI18nExceptionFilter— catchesHttpExceptions carrying anapiErrorbody, localizesmessagevia the resolver using the request'sctx.lang, emits the{ error: { code, message, data } }envelope.codeis preserved for client-side handling.SimpleI18nResolver— catalog lookupcatalogs[lang][code] → catalogs[fallback][code] → code, with{var}interpolation fromdata(+ Zod issueparams). For ICU / plurals, implement a customII18nResolver.DefaultLanguageResolver— parses the rawAccept-Languageheader (vi-VN,vi;q=0.9,en;q=0.8) to a supported base code, q-sorted, with fallback.- Built-in catalogs — en + vi messages for every
core.*code the library throws, shipped inCORE_CATALOGS. Merge your app's catalog over them.
Enable via the i18n key (opt-in — omit to leave envelopes untranslated):
ts
SdCoreModule.forRoot({
i18n: {
fallbackLanguage: 'vi',
supportedLanguages: ['en', 'vi'],
catalogs: { // merged OVER built-in core.* (consumer wins)
vi: { 'app.product.name.min': 'Tên phải có ít nhất {minimum} ký tự' },
},
// resolver: MyIcuResolver, // optional: replace SimpleI18nResolver entirely
// useGlobalFilter: false, // optional: skip the global APP_FILTER
},
});ApiResponse.ok(data) / ApiResponse.noContent() wrap successful responses.