0

I'm trying to get an Url object with correct interface language.

use Drupal\Core\Url;

$language_manager = \Drupal::service('language_manager');
$url = Url::fromRoute(
  "entity.node.content_translation_add",
  [
    'node' => 1,
    'source' => 'en',
    'target' => 'fr',
  ],
    ['language' => $language_manager->getLanguage('fr')]
  );

However, when I try $url->toString() i get:

/node/1/translations/add/en/fr

but it should be:

fr/node/1/translations/add/en/fr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.