The above page says:
// If the node has no Spanish translation, this also adds one. If it does // already have a Spanish translation, it will update the title. $node->getTranslation('es')->title->value = 'Spanish title'; $node->save();
I gave this a try on 8.2.4 and it yields an exception:
exception 'InvalidArgumentException' with message 'Invalid translation language (es) specified.' in
In my case $node exists and does not have an 'es' translation prior to executing the sequence above. The website does have the 'es' language configured.
The following sequence does work in the same situation:
$node = $node->hasTranslation('es') ? $node->getTranslation('es') : $node->addTranslation('es'); $node->title->value = "Spanish $alias"; $node->save();
Please change the code to accommodate this case -- or change the tidbits-19 web page.