A modern, ready-to-use starter project for building multilingual, well-structured REST APIs with NestJS.
✨ Features:
- 🌐 Internationalization (i18n) using i18next
- ✅ Centralized validation error handling with dynamic message interpolation
- 🛡️ Global
HttpExceptionFilterwith consistent API error responses - 🗣️
Accept-Languageheader support via aLanguageInterceptor - 🗃️
RequestContextfor per-request language scoping - 🔐 Google OAuth login flow
- 📚 Clean and extensible
TranslationServiceusing i18next core - 🚀 Designed to be lightweight and free of unnecessary dependencies (no
nestjs-i18npackage required)
Most i18n NestJS examples rely on nestjs-i18n, which is great but often overkill for APIs.
This starter project demonstrates a lightweight, fully controlled way to integrate:
- i18next directly
- Validation with dynamic placeholders (e.g.,
{{max}},{{min}},{{length}}) - Clean API response patterns
- Authentication via Google OAuth
- ✅ TranslationService — wraps and initializes
i18next - ✅ I18nextValidationPipe — extends
ValidationPipe, adds automatic arg completion for common constraints (minLength,maxLength,equals,length, etc.) - ✅ HttpExceptionFilter — consistent error responses with proper translation
- ✅ LanguageInterceptor — populates
RequestContext.langbased onAccept-Languageheader - ✅ Validation messages — stored in
i18n/{{lng}}/validation.json - ✅ Google OAuth — integrated as a flexible auth provider
src/
├── common/
│ ├── context/ → RequestContext
│ ├── exceptions/ → I18nValidationException
│ ├── filters/ → HttpExceptionFilter
│ ├── interceptors/ → LanguageInterceptor
│ ├── pipes/ → I18nextValidationPipe
│ ├── services/ → TranslationService
│ └── helpers/ → Utility helpers (BaseResponse, etc.)
├── enums/ → Translation groups, API error codes
├── i18n/ → Translations (validation.json, messages.json)
└── auth/ → Google OAuth flow, DTOs, controllers
@MaxLength(10)
@MinLength(6)
@IsNotEmpty()
@IsEmail()- No need to pass
{ max }or{ min }— handled automatically byI18nextValidationPipe. - Validation messages pulled from
validation.json.
{
"fieldErrors": [
{
"field": "password",
"message": "Must be at most 10 characters."
}
]
}- Full control of
i18nextintegration - No additional package dependency
- Easier to fine-tune behavior for API-specific needs
- Works seamlessly with
ValidationPipeandHttpExceptionFilter
- ✅ i18n with i18next
- ✅ ValidationPipe auto-args
- ✅ BaseResponse + consistent API error contract
- ✅ Google OAuth login flow
- ✅ Ready for production use
🔧 Possible future improvements:
- i18n caching
- Multi-namespace support with dynamic loading
- Support for more advanced i18next plugins
git clone https://github.com/iibalena/nestjs-api-i18n-auth-starter.git
cd nestjs-api-i18n-auth-starter
npm install
npm run start:devMIT
Feel free to fork, star, and contribute via PRs! Feedback and ideas are always welcome.
Developed by Ivonei Balena with ❤️