REST: Translations
Overview
A form's texts can differ per store view: a field's label, placeholder or validation message in German on the German store view, for example. GET /V1/webforms/forms/{formId}/translations/{storeCode} returns those store view texts of the live form for one store view. Writing them goes through a draft with the set-translations command; the texts reach the live form when the draft is published.
The answer has store_code and translations_json, a JSON string with these members:
| Member | Holds |
|---|---|
form | Store view values of the form's own settings |
fieldsets | Store view values per section, keyed by section id |
fields | Store view values per field, keyed by field id |
logic | Store view trigger values per logic rule, keyed by rule id |
defaults | For each translatable text left empty, the storefront phrase the store view shows in its place, grouped like the members above (form, fieldsets, fields); left out when there is none. %1 stays a placeholder |
defaults_locale | The locale of the store view the phrases are in |
The ids are those of the live form. A member with nothing in it is an empty JSON array ([]), not an object. Only settings marked translatable in REST: Schema are returned, plus structured settings such as a field's choices (its Options).
What counts as translatable
The schema decides. For fields, the visible texts are translatable: name, placeholder, comment, tooltip, result_label, the validation messages, and choices. For sections, name and subtitle. On the form itself only reference_number_prefix and reference_number_suffix are translatable.
Other form settings, such as submit_button_text, can still differ per store view: write them with update-form and store_code (see REST: Drafts) and read them with GET /V1/webforms/forms/{formId}/document?storeCode={storeCode}. They do not appear in the translations.
Writing translations
POST /V1/webforms/drafts/{draftId}/commands/set-translations with:
| Key | Meaning |
|---|---|
request_id, expected_draft_revision | As for every draft command |
store_code | The store view; required, and admin is not accepted |
translations_json | The same four members as the read. Sections, fields and rules are referenced by their draft id; fields also by code |
mode | replace replaces the store view values of each entity you send; anything else merges into them |
In a merge, a key set to null removes that store view value, so the default text applies again. replace touches only the entities in the request; the store view values of the others stay, and so do the keys of an entity that are not translations. The answer's payload is {"entities_written": n}.
A value equal to the phrase in defaults, written on top of an empty base text, is not stored: the store view keeps following the phrase. Such a text takes only the placeholders its phrase has. The same rules apply when update-form, update-fieldset or update-field write a store view text.
A logic rule's store view values must be Options that the trigger field offers on that store view.
Authentication
OAuth 1.0a integration credentials, as described on REST API. Reading translations needs forms_view; set-translations and publishing the draft need forms_edit.
Operations
| Method | Path | Operation | ACL resource |
|---|---|---|---|
| GET | /V1/webforms/forms/{formId}/translations/{storeCode} | FormReadInterface_getTranslations | MageMe_WebForms::api_v1_forms_view |
set-translations is a draft command, sent to POST /V1/webforms/drafts/{draftId}/commands/{name} (listed on REST: Drafts).
Errors
| Code | HTTP | When |
|---|---|---|
NOT_FOUND | 404 | No such form, a form outside the integration's form scope, a draft id instead of a live form id, or an unknown store code (Unknown store "…"., also for admin) |
VALIDATION_FAILED | 400 | set-translations: a key that is not translatable, named with its element of translations_json (form: "name" is not translatable., fields[<ref>]: "columns" is not translatable., also fieldsets[…] and logic[…]); a placeholder the phrase has no value for ("min_length_validation_message" may use only the placeholders %1; %2 has no value there.); or no store_code (store_code is required for translations.) |
DRAFT_REVISION_MISMATCH | 409 | set-translations: expected_draft_revision is stale |
The refusals every route shares are listed on REST API.
Examples
One sequence on form 995589, on a store view with the code de. The draft is 995590, opened as described on REST: Drafts.
Set German texts for one section and three fields, by section id and field codes:
curl -X POST https://yourdomain.com/rest/all/V1/webforms/drafts/995590/commands/set-translations \
-H "Authorization: <signed-header>" -H "Content-Type: application/json" \
-d @translations.json
translations.json:
{
"request": {
"request_id": "erp-de-0001",
"expected_draft_revision": 0,
"store_code": "de",
"translations_json": "{\"fieldsets\":{\"9920313\":{\"name\":\"Ihre Angaben\"}},\"fields\":{\"message\":{\"name\":\"Nachricht\",\"placeholder\":\"Wie können wir helfen?\"},\"email\":{\"name\":\"E-Mail\"},\"customer_name\":{\"name\":\"Name\"}}}"
}
}
{"draft_id": 995590, "draft_revision": 1, "changed": true, "payload_json": "{\"entities_written\":4}"}
Remove the German name of customer_name again, so the default label applies (a merge with null):
{"request": {"request_id": "erp-de-0002", "expected_draft_revision": 1, "store_code": "de", "translations_json": "{\"fields\":{\"customer_name\":{\"name\":null}}}"}}
Replace the German values of message. Its placeholder is dropped; the other fields keep theirs:
{"request": {"request_id": "erp-de-0003", "expected_draft_revision": 2, "store_code": "de", "mode": "replace", "translations_json": "{\"fields\":{\"message\":{\"name\":\"Ihre Nachricht\"}}}"}}
A setting that is not translatable:
{"message": "\"submit_button_text\" is not translatable.", "parameters": {"code": "VALIDATION_FAILED", "details_schema_version": "1", "details_json": "{}"}}
After the draft is published, read the German texts of the live form:
curl https://yourdomain.com/rest/all/V1/webforms/forms/995589/translations/de \
-H "Authorization: <signed-header>"
{"store_code": "de", "translations_json": "{\"form\":[],\"fieldsets\":{\"9920311\":{\"name\":\"Ihre Angaben\"}},\"fields\":{\"99192558\":{\"name\":\"E-Mail\"},\"99192553\":{\"name\":\"Ihre Nachricht\"}},\"logic\":[]}"}
The section and the fields now carry their live ids (9920311 instead of the draft's 9920313). A store view without texts of its own answers:
{"store_code": "default", "translations_json": "{\"form\":[],\"fieldsets\":[],\"fields\":[],\"logic\":[]}"}