API: Translations & Data
Relevant source files
The following files were used as context for generating this wiki page:- api/src/controllers/term.controller.ts
- api/src/controllers/translation.controller.ts
- api/src/controllers/import.controller.ts
- api/src/controllers/exports.controller.ts
- api/src/domain/http.ts
- api/test/import.e2e-spec.ts
- api/test/export.e2e-spec.ts
- api/test/term.e2e-spec.ts
- api/test/translation.e2e-spec.ts
The Traduora API provides a comprehensive set of REST endpoints for managing all aspects of translation data. This includes the core entities of terms (the keys to be translated), locales (the languages), and translations (the translated values). The API is designed to automate translation workflows, allowing for programmatic creation, retrieval, updating, and deletion of translation data.
A key feature of the API is its robust import and export functionality. Users can bulk-add or update translations from various standard file formats, and similarly export project data for use in applications or for backup. This allows seamless integration with existing development and localization pipelines. All data management is scoped to a specific project, and access is controlled via authentication and authorization.
Sources: README.md, api/src/controllers/import.controller.ts, api/src/controllers/exports.controller.ts
Core Data Models
The API revolves around a few central entities that represent the translation data structure.
The diagram below illustrates the relationships between the main data entities managed by the API.
Term*: Represents a unique key or string to be translated (e.g., app.title). It can also have an optional context for disambiguation.
- Locale: A standard language/region code (e.g.,
en_US,fr). - ProjectLocale: Links a
Localeto aProject, enabling that language within the project. - Translation: The actual translated string for a specific
Termin a specificProjectLocale.
Sources: api/src/domain/http.ts:161-174, api/src/controllers/term.controller.ts, api/src/controllers/translation.controller.ts
Terms Management
The API provides full CRUD (Create, Read, Update, Delete) functionality for managing terms within a project. Terms are the fundamental keys for your translations.
Sources: api/src/controllers/term.controller.ts
API Endpoints for Terms
| Method | Endpoint | Description |
|---|---|---|
POST | /api/v1/projects/{projectId}/terms | Creates a new term in the specified project. |
GET | /api/v1/projects/{projectId}/terms | Retrieves all terms for a project, in lexical order. |
PATCH | /api/v1/projects/{projectId}/terms/{termId} | Updates an existing term's value or context. |
DELETE | /api/v1/projects/{projectId}/terms/{termId} | Deletes a term from the project. |
Sources: api/src/controllers/term.controller.ts, api/test/term.e2e-spec.ts:100-113
Data Structures
AddTermRequest
When creating a term, the following payload is expected:
| Field | Type | Required | Description |
|---|---|---|---|
value | string | Yes | The term key (e.g., "login.button"). Max 255 chars. |
context | string | No | Optional context for the term. Max 1000 chars. |
Sources: api/src/domain/http.ts:503-514
ProjectTermDTO (Response)
The API responds with a ProjectTermDTO object upon successful creation or retrieval.
| Field | Type | Description |
|---|---|---|
id | string | The unique identifier for the term. |
value | string | The term key. |
context | string | The context provided for the term. |
labels | array | An array of labels associated with the term. |
date | object | Creation and modification timestamps. |
Sources: api/src/domain/http.ts:161-174
Translations & Locales Management
These endpoints manage the languages (locales) available in a project and the corresponding translation values for each term.
Sources: api/src/controllers/translation.controller.ts
API Endpoints for Locales & Translations
| Method | Endpoint | Description |
|---|---|---|
POST | /api/v1/projects/{projectId}/translations | Adds a new locale (language) to the project. |
GET | /api/v1/projects/{projectId}/translations | Lists all locales added to the project. |
GET | /api/v1/projects/{projectId}/translations/{localeCode} | Retrieves all translations for a specific locale. |
PATCH | /api/v1/projects/{projectId}/translations/{localeCode} | Creates or updates a translation value for a specific term and locale. |
DELETE | /api/v1/projects/{projectId}/translations/{localeCode} | Deletes a locale and all its associated translations from the project. |
Sources: api/src/controllers/translation.controller.ts, api/test/translation.e2e-spec.ts
Data Structures
AddLocaleRequest
To add a new language to a project:
| Field | Type | Required | Description |
|---|---|---|---|
code | string | Yes | The locale code (e.g., "de_DE"). |
Sources: api/src/domain/http.ts:516-521
UpdateTranslationRequest
To add or update a translation for a term:
| Field | Type | Required | Description |
|---|---|---|---|
termId | string | Yes | The ID of the term to translate. |
value | string | Yes | The translated string. Max 8192 chars. UTF-8 supported. |
Sources: api/src/domain/http.ts:528-537, api/test/translation.e2e-spec.ts:182-194
Data Import
The import API allows for bulk creation and updating of terms and translations from a single file. This is useful for migrating data from other systems or integrating with a CI/CD pipeline.
Sources: api/src/controllers/import.controller.ts
Import Process Flow
The import process handles file parsing, authorization, and data persistence within a single database transaction to ensure data integrity.
This diagram shows the sequence of operations when a user imports a translation file.
If the import would exceed the project's plan limits (e.g., maximum number of strings), the entire operation is rolled back and a 402 Payment Required error is returned.
Sources: api/src/controllers/import.controller.ts:80-81, 120-121, 152-156, api/test/import.e2e-spec.ts:311-315
API Endpoint for Import
- Method:
POST - Endpoint:
/api/v1/projects/{projectId}/imports - Content-Type:
multipart/form-data
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
locale | string | Yes | The locale code for the translations in the file. |
format | string | Yes | The format of the file being imported. See supported formats. |
Sources: api/src/domain/http.ts:566-575
Response Body
The API returns a summary of the import operation.
{
"data": {
"terms": {
"added": 1,
"skipped": 1
},
"translations": {
"upserted": 2
}
}
}
Sources: api/test/import.e2e-spec.ts:214-225
Data Export
The export API allows for downloading all terms and their translations for a specific locale in various file formats.
Sources: api/src/controllers/exports.controller.ts
Export Process Flow
This diagram shows the sequence of operations when a user requests to export translations.
API Endpoint for Export
- Method:
GET - Endpoint:
/api/v1/projects/{projectId}/exports
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
locale | string | Yes | The locale code to export. |
format | string | Yes | The desired output file format. See supported formats. |
fallbackLocale | string | No | A locale to use for translations if the primary locale does not have a translation for a term. |
untranslated | boolean | No | If true, exports only terms that have empty translations for the specified locale. |
Sources: api/src/domain/http.ts:551-564
The API responds with the file as an application/octet-stream. The terms in the exported file are sorted in lexical order.
Sources: api/src/controllers/exports.controller.ts:138-140, api/test/export.e2e-spec.ts:124-133
Supported Formats
The import and export functionalities support a wide range of common localization file formats.
| Format Key | Name |
|---|---|
androidxml | Android Resources (.xml) |
csv | CSV |
jsonflat | JSON (flat key-value) |
jsonnested | JSON (nested objects) |
po | Gettext (.po) |
properties | Java Properties |
php | PHP Array |
resx | .NET Resource file (.resx) |
strings | Apple Strings (.strings) |
xliff12 | XLIFF 1.2 |
yamlflat | YAML (flat key-value) |
yamlnested | YAML (nested objects) |
Sources: api/src/domain/http.ts:539-550, README.md
Summary
The Translations & Data API provides a powerful and flexible interface for managing localization data. Through its well-defined endpoints for terms, translations, and locales, combined with extensive import/export capabilities, it enables developers to build automated and efficient translation workflows. The transactional nature of data operations and adherence to project plan limits ensures both data integrity and compliance with usage quotas.