Feature: Translation Workflow
Relevant source files
The following files were used as context for generating this wiki page:
- api/src/controllers/translation.controller.ts
- webapp/src/app/projects/components/translations-list/translations-list.component.html
- webapp/src/app/projects/stores/translations.state.ts
- api/src/controllers/import.controller.ts
- api/domain/http.ts
- api/test/translation.e2e-spec.ts
- api/test/import.e2e-spec.ts
- README.md
The Translation Workflow is a core feature of the Traduora platform, designed to facilitate the management of multilingual content for software projects. It allows teams to define translatable keys (Terms), add multiple languages (Locales), and provide the corresponding string values (Translations). The workflow is supported by a REST API for backend operations and an Angular-based web application for the user interface.
Key functionalities include creating and managing project locales, adding and updating translations for each term, and importing/exporting translation files in various formats. This system ensures that as new terms are added to a project, placeholders are automatically created for each supported locale, streamlining the process for translators.
Core Components & Data Model
The translation workflow revolves around several key entities: Projects, Terms, Locales, and Translations. Their relationships are central to how the system operates.
This ER diagram illustrates the relationships between the main entities involved in the translation workflow.
API Endpoints
The backend exposes a set of RESTful endpoints for managing all aspects of the translation workflow. These are primarily handled by the TranslationController and ImportController.
Translation Management (TranslationController)
This controller manages the lifecycle of project locales and their associated translations.
Sources: api/src/controllers/translation.controller.ts
| Method | Endpoint | Description - |
|---|---|---|
GET | / | Lists all translation locales for a project. - |
POST | / | Adds a new translation locale to a project. When a new locale is added, it automatically creates empty translation entries for all existing terms in that project. - |
GET | /:localeCode | Retrieves all translated terms for a specific locale within a project. - |
PATCH | /:localeCode | Updates a specific term's translation for a given locale. If the translation does not exist, it is created. - |
DELETE | /:localeCode | Deletes a project's locale and all associated translations. - |
Import Management (ImportController)
This controller handles the bulk import of translation files.
Sources: api/src/controllers/import.controller.ts
| Method | Endpoint | Description - |
|---|---|---|
POST | /imports | Imports a translation file for a given locale and format. It can create new terms and will create the project locale if it doesn't exist. It overwrites existing translation values. |
Supported Import/Export Formats
The platform supports a wide range of formats for importing and exporting translation data.
Sources: api/domain/http.ts:316-329, README.md:27-28
| Format Enum | Display Name |
|---|---|
androidxml | Android Resources |
csv | CSV |
xliff12 | XLIFF 1.2 |
jsonflat | JSON Flat |
jsonnested | JSON Nested |
yamlflat | YAML Flat |
yamlnested | YAML Nested |
properties | Java Properties |
po | Gettext (po) |
strings | Strings |
php | PHP |
resx | ResX |
Frontend State Management (NGXS)
The web application uses NGXS for state management. The TranslationsState is responsible for managing all data related to project locales and translations on the client side. It orchestrates API calls and updates the local state, which components then subscribe to.
Sources: webapp/src/app/projects/stores/translations.state.ts
This diagram shows the sequence of events when a user updates a translation value in the UI.
Key NGXS Actions
The TranslationsState defines several actions to interact with the API and manage the client-side state.
| Action | Description - |
|---|---|
GetProjectLocales | Fetches all locales associated with a specific project. - |
AddProjectLocale | Adds a new locale to a project. - |
DeleteProjectLocale | Removes a locale from a project. - |
GetTranslations | Fetches all translations for a given project and locale. - |
UpdateTranslation | Dispatches a request to update a single translation value. - |
Sources: webapp/src/app/projects/stores/translations.state.ts:20-57
Key Workflow Scenarios
Adding a New Project Locale
Adding a new locale to a project is a foundational step. This process involves both the frontend and backend.
- A user initiates the action from the web UI.
- The
TranslationsStatedispatches anAddProjectLocaleaction. - This triggers a
POSTrequest to/api/v1/projects/:projectId/translations. - The
TranslationControllerhandles this request. It first validates the locale code. - Within a database transaction, it creates a new
ProjectLocaleentity. - Crucially, it then fetches all existing
Termentities for the project and creates a new, emptyTranslationentity for each term, associating it with the newProjectLocale. - This ensures that the new language is immediately ready for translators, with all required terms present.
The following diagram shows the flow for adding a new locale to a project.
Updating a Translation
Translators spend most of their time updating individual translation values.
- A user edits a translation in the
TranslationsListComponent. - The component's
updateTranslationmethod is called, which dispatches anUpdateTranslationaction to the NGXS store. - The
TranslationsStatehandles the action, calling theProjectTranslationsService. - The service sends a
PATCHrequest to/api/v1/projects/:projectId/translations/:localeCode. - The
TranslationController.updatemethod finds the correspondingProjectLocaleandTerm. - It then updates the
valueof theTranslationentity or creates a new one if it doesn't exist. - The updated translation is saved to the database and returned to the client, which updates the UI.
Sources: webapp/src/app/projects/components/translations-list/translations-list.component.html:56-63, api/src/controllers/translation.controller.ts:138-188, webapp/src/app/projects/stores/translations.state.ts:168-202
Importing Translations
The import feature allows for bulk updates from a file.
- A user uploads a file and selects the format and destination locale via the
import-localecomponent. - A
POSTrequest is sent to/api/v1/projects/:projectId/imports. - The
ImportController.importmethod receives the file and query parameters (locale,format). - It uses a parser (e.g.,
jsonFlatParser,csvParser) based on theformatquery parameter to convert the file content into a standardizedIntermediateTranslationFormat. - Within a database transaction, it performs the following:
- Checks if the
ProjectLocaleexists. If not, it creates it. - Identifies which terms from the import file are new and creates
Termentities for them. - Upserts
Translationentities, matching incoming terms to existing or newly created terms and updating their values for the specified locale.
- Checks if the
- It returns a summary of added/skipped terms and upserted translations.
Sources: api/src/controllers/import.controller.ts:47-151, webapp/src/app/projects/components/import-locale/import-locale.component.html, api/test/import.e2e-spec.ts:153-172
Conclusion
The translation workflow in Traduora is a robust system built on a clear data model and a well-defined API. The separation of concerns between the API backend (handling business logic and data persistence) and the web frontend (managing state and user interaction) allows for an efficient and scalable translation management process. The inclusion of bulk import/export functionality and the automatic creation of translation placeholders upon adding new locales are key features that streamline the localization process for development teams.