Create link to node in specific language So I need to create links to specific translations of a node but am having issues.
This is my code:
foreach($entities as $entity) {
$urls[] = Url::fromRoute('entity.node.canonical', [
        'node' =&gt; $entity-&gt;id(),
        'language' =&gt; $entity-&gt;language()-&gt;getId(),
      ]);
}

$entity in this context is EntityInterface.
But this gives me /node/1185?language=es instead of /es/node/1185.
$entity-&gt;toUrl('canonical', ['language' =&gt; $entity-&gt;language()]);
Taken from this question thread