Translations management API¶
Translations management offers the following ways to work with translations outside the back office:
- PHP API - find content that misses a translation, work with bulk translation jobs and review statuses, and read translation analytics
- REST API - do everything that the Translations screen of Translations hub does, including starting bulk translation jobs
- console commands - translate single content items and maintain translation data
PHP API¶
The PHP API services of Translations hub let you build your own reports or automate the review of bulk translation jobs:
ContentDiscoveryServiceInterfacefinds content items that miss a translationJobServiceInterfacereads bulk translation jobs and their items, and reviews, retries, and removes themReviewItemServiceInterfacelists machine translations by review status, both from bulk translation jobs and from individual translationsTranslationCoverageProviderInterface,TranslationBacklogProviderInterface, andTranslationStaleOwnersProviderInterfacereturn translation analytics
All of them respect the permissions of the current user. For more information, see Translations hub permissions.
To start bulk translation jobs, use the REST API.
Find content that misses translation¶
ContentDiscoveryServiceInterface::findMissingTranslations() returns the content items that don't have a published version in the target language, and that the current user can translate into it.
Like the Missing tab, it searches the content structure and leaves out products.
Pass a ContentDiscoveryQuery with the target language code.
You can also filter the results by content type identifier and by a search phrase, and set sorting and pagination.
The method returns a SearchResult with Content objects.
Read translation analytics¶
The analytics providers return the data that the Analytics screen of Translations hub shows.
Without a SubtreeCriterion, they cover the whole content structure, and they count only the content items that the current user can read.
| Provider | Query | Returns |
|---|---|---|
TranslationCoverageProviderInterface::getTranslationCoverage() |
TranslationCoverageQuery |
For each language, the number of content items that are translated, missing, or outdated, the coverage ratio, and the average number of times the source was published again after the outdated translations |
TranslationBacklogProviderInterface::getTranslationBacklog() |
TranslationBacklogQuery |
Content items that need a new translation or an update of an outdated one |
TranslationStaleOwnersProviderInterface::getStaleOwnerIds() |
TranslationStaleOwnersQuery |
IDs of the owners of content items with an outdated translation |
You can narrow the results with criteria from the Ibexa\Contracts\TranslationsManagement\Analytics\Query\Criterion namespace, for example, by subtree, content type, or publication date.
Not every provider supports every criterion: an unsupported criterion results in an UnsupportedCriterionException.
The following example prints the translation coverage of a language and the first content items that miss a translation into it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
Work with bulk translation jobs¶
JobServiceInterface gives access to the jobs listed in the History tab of Translations hub:
findBulkTranslationJobs()andcountBulkTranslationJobs()find jobs by status, target language, creator, or title, by using aJobQuerygetBulkTranslationJob()loads a job by its IDfindJobItems()lists the items of a job, optionally filtered by item status, review status, target language, or content type, by using aJobItemQueryreviewBulkTranslationJobItems()approves or rejects the translations of many job items at onceretryBulkTranslationJob()translates the failed items of a finished job againretranslateJobItem()translates a single item of a finished job again, and removes its previous draftremoveBulkTranslationJob()removes a job together with the drafts that it created, or cancels it first if it's pending or in progress
Retrying, translating again, and removing happen in the background.
The following example lists the jobs that wait for review or failed, together with their failed items, and can retry the failed items or approve all translations of a job:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
Find translations by review status¶
ReviewItemServiceInterface::findReviewItems() returns machine translations, like the For review and Translated tabs do.
Unlike JobServiceInterface::findJobItems(), it includes translations that editors created one by one, outside of bulk translation jobs.
Pass a ReviewItemQuery with criteria from the Ibexa\Contracts\TranslationsManagement\ReviewQueue\Values\Criterion namespace, for example ReviewStatusCriterion, TargetLanguageCriterion, JobIdCriterion, or ProviderCriterion, and combine them with LogicalAnd and LogicalOr.
Each returned ReviewItem contains the content ID, version number, languages, provider, review status, and, for translations from a bulk translation job, the job context.
REST API¶
The REST API of Translations hub covers everything that the Translations screen does, including starting bulk translation jobs.
Its endpoints are available under /api/ibexa/translations-hub/bulk-translation/:
| Method | Endpoint | Description |
|---|---|---|
GET |
/missing |
List content items that miss a translation |
GET |
/missing/ids |
List the IDs of content items that miss a translation, for selecting them in a job |
GET |
/missing/filters |
List the filter choices of the missing translations list |
GET |
/outdated |
List outdated translations |
GET |
/outdated/filters |
List the filter choices of the outdated translations list |
POST |
/setup |
Preview a bulk translation job for the selected content items, without creating it |
POST |
/start |
Start a bulk translation job |
GET |
/history |
List bulk translation jobs |
GET |
/history/filters |
List the filter choices of the job list |
GET |
/job/{id} |
Get the summary of a job |
GET |
/job/{id}/items |
List the items of a job |
POST |
/job/{id}/retry |
Retry the failed items of a job |
DELETE |
/job/{id} |
Remove a job |
POST |
/job-items/{id}/retranslate |
Translate a single job item again |
POST |
/job-items/bulk-review |
Approve or reject the translations of many job items |
GET |
/for-review |
List translations that wait for review |
GET |
/for-review/filters |
List the filter choices of the review list |
GET |
/translated |
List accepted translations that aren't published yet |
GET |
/translated/filters |
List the filter choices of the accepted translations list |
POST |
/translated/bulk-delete |
Delete the drafts of many accepted translations |
To start a job, send the IDs of the content items, the source language, the target languages, and the provider identifier, for example:
1 2 3 4 | |
If no enabled translation provider supports the language pair, omit provider or set it to null.
The job then creates empty drafts in the target languages, with the "For review" status, for editors to translate.
The response says whether a job was started, its ID, and how many content items were accepted or skipped.
The job leaves out content items that don't exist, products, and content items that the user can't translate, and, unless includeExistingTranslations is true, content items that already have all the target translations.
One job can contain at most 500 translations, counted as content items multiplied by target languages.
If a job for one of the target languages is already pending or in progress, the request fails with the 409 Conflict status.
These endpoints use the same authentication as the rest of the REST API.
With session authentication, requests that change data must contain the X-CSRF-Token header.
The REST API reference doesn't list these endpoints. To get their full OpenAPI description, with request and response schemas, export it from your project:
1 | |
Console commands¶
Translate content items¶
For the purposes of batch processing, automation, and other scripted actions, the Translations management package exposes a command that automatically translates content items or products by using any of the configured providers:
1 2 3 4 5 | |
Command alias
You can use ibexa:translations:translate-content as an alias.
The command uses the same provider configuration and field value transformers as the UI. Therefore, depending on the specific command options used, the result can be the same as if an editor triggered the automated translation manually.
Without the --draft-only option, the translation generated with a CLI command is instantly published, while a manual one requires that a human publishes it.
Command options¶
| Option | Required | Description |
|---|---|---|
--content-id |
Yes | ID of the content item or product to translate |
--provider |
Yes | Identifier of the translation provider to use |
--from |
Yes | Source language code |
--to |
Yes | Target language code |
--user-id |
No | Repository user ID to run the translation (default: 14, which is the Administrator user) |
--draft-only |
No | Create a translated draft without publishing it |
Purge translation attempts¶
Cohesivo records every attempt to translate a content item with a translation provider, including attempts that failed. Provider statistics in analytics use these records to calculate how often requests to each provider fail.
To remove attempts older than a specific number of days, run the ibexa:translations:purge-translation-attempts command.
By default, it removes attempts older than 365 days.
First, list the attempts that the command would remove:
1 | |
Then, remove them:
1 | |
Without --dry-run or --force, the command doesn't remove anything.
After a purge, provider statistics no longer include the removed attempts.
Reset stuck removals¶
When a user deletes a bulk translation job, or deletes drafts in the Translated tab, the job or the drafts disappear from the list while the worker removes them in the background. If the removal doesn't finish, for example because the message was lost, you can list them again so that users can repeat the action:
-
To list bulk translation jobs in the History tab again, run
ibexa:translations:reset-pending-job-removalswith job IDs, or with the--alloption:1php bin/console ibexa:translations:reset-pending-job-removals 12 15 -
To list translations in the Translated tab again, run
ibexa:translations:reset-pending-draft-removalswith the IDs of auto-translation records, or with the--alloption:1php bin/console ibexa:translations:reset-pending-draft-removals --all