Programmatically add a translation with proper content moderation state I am trying to add a node translation programmatically when a node is created (using hook_ENTITY_TYPE_insert). My code works fine except that the translation doesn't really have a content moderation state. My code is the following.
function mymodule_add_translation($node) {
  // get the current language, and determine the translation language
  $lang = \Drupal::languageManager()-&gt;getCurrentLanguage()-&gt;getId();
  $langcode = ($lang == 'en') ? 'fr' : $lang;
  $node-&gt;setRevisionTranslationAffected(FALSE);
  $node-&gt;addTranslation($langcode, ['title' =&gt; $node-&gt;getTitle()])-&gt;save();
}

This is what the content_moderation_state_field_revision table looks like for two nodes; the first one was manually translated and the second one was translated using the above code.



I am clearly doing something incorrect. Any suggestion would be really appreciated.
What is the problem you're seeing with the moderation state table? What I think I'm seeing is:

Revision 15 is the initial save of the node.
Revision 16 is the second save, where fr has changes and en does not.

I can't see anything too unusual here, but if you are running into errors later in the lifecycle of the node, that would be helpful information.
One red flag I can see in the code is manually calling setRevisionTranslationAffected and addTranslation. Many of the Content Moderation tests use the following methods to add translations and to create revisions, because that's how additional bits of metadata like the revision_translation_affected column are set:
$storage = \Drupal::entityTypeManager()-&gt;getStorage('node');
// You may try either of these two methods for creating a revision or a translation.
$storage-&gt;createRevision($node);
$storage-&gt;createTranslation($node, 'fr', $node-&gt;toArray());