Overview
Translations created by Canvas Translate keep und as their translation source metadata. ApiTranslateController::applyDraftToTarget() (1.0.x, lines 819–820) intends to set content_translation_source when publishing a draft, guarded by $target->get('content_translation_source')->isEmpty(). The guard never fires: the target translation is created with addTranslation($langcode, $stored->toArray()), which copies the source entity's content_translation_source value — und, the field's default. und is a value, not an empty field, so isEmpty() returns FALSE.
Two consequences:
- The translate overview shows an unknown source for translations created by this module.
- Any later code that saves such a translation object directly — while the field has
content_translationtranslation_syncsettings, which Canvas pages have by default since canvas#3591745 — triggers core'sFieldTranslationSynchronizerexception:Invalid translation language (und) specified. Canvas Translate itself is not affected (it saves through the default translation), but the storedundis a latent trap for other modules and custom code.
Steps to reproduce
- Install canvas, canvas_translate, language, content_translation; add a second language; enable translation for Canvas pages.
- Create a Canvas page, translate it with Canvas Translate, publish the translation.
- Inspect the translation's
content_translation_sourcefield: it isundinstead of the source langcode.
Proposed resolution
Compare against LanguageInterface::LANGCODE_NOT_SPECIFIED instead of (or in addition to) isEmpty(), so the source langcode is written both when the field is empty and when it holds the und default.
User interface changes
None.
Issue fork canvas_translate-3609434
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #5
lauriii