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(
    'node' => 1,
    'source' => 'en',
    'target' => 'fr',
    ['language' => $language_manager->getLanguage('fr')]

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


but it should be:


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.