How cuongpq-dgh/nestjs-localization-module works
This project is a dynamic NestJS module designed to provide localization support for NestJS applications. Its primary purpose is to manage translations through a set of RESTful APIs, integrate with a PostgreSQL (or other SQL) database via TypeORM for persistence of language and translation entities, and optionally leverage the Microsoft Translator API for automatic translation. The module is configurable via its forRoot() method, making it both flexible and pluggable in larger applications.
Main Components
• Dynamic Module Configuration: Represent the module setup where the module is configured via forRoot() (with options for an existing TypeORM connection, API prefix, cache, default language, and an optional authentication guard).
• Controllers: Include separate controllers such as ConfigController, LanguageController, Third-Party-ConfigController, and Translation-related controllers. They are responsible for handling API requests related to configuration, languages, and translations.
• DTOs (Data Transfer Objects): Represent all the DTOs defined under the src/dtos directory. These include creation, update, filtering, and batch-processing DTOs for languages, translations, and third-party configurations.
• Entities: Show the entity layer with objects like config.entity, language.entity, third-party-config.entity, translation.entity, and translations.entity. These represent the database tables mapped through TypeORM.
• Services: Highlight the service layer which includes LanguageService, TranslationsService, Third-Party-ConfigService, and MicrosoftTranslatorService. These components encapsulate the business logic, data handling, and integration with external APIs.
• Guards and Pipes: Illustrate the presence of custom Guard (localization-auth.guard) for security and validation Pipe (parse-string-param.pipe) for processing route parameters.
• Utility Components: Optionally include utilities like short-uuid.util for any auxiliary function.
Relationships and Interactions
• Data Flow Through DTOs: Illustrate that the submitted data is first mapped and validated using DTOs before being forwarded to the service layer.
• Configuration Flow: Show that configuration (like third-party API keys and database connection options) is first set via module configuration and then used throughout the system (by the controllers and services).
Architectural Patterns and Design Principles
• Layered Architecture: Emphasize the separation of concerns among Controllers, DTOs, Services, and Entities.
• RESTful API Design: Highlight that the controllers expose a well-defined set of endpoints for translations and languages.
Technology, Frameworks, and Libraries
• TypeORM: Illustrate that the entity layer interacts with the database through TypeORM.
• Microsoft Translator API: Denote the integration with external translation services.
• Optional Components: If relevant, show integration points with i18next for the client-side usage as per the README examples.