How to get language specific path in twig? In a twig template you are able to get a relative path by using {{ path('entity.node.edit_form', {'node': nid }) }}. The path will be in current language.

Now I need to get the path in a specfic language. I thought I could use {{ path('entity.node.edit_form', {'node': nid }, {'language': langcode}) }} but this results an error if I set langcode to a string like DE. According to the api docs language has to be a language object. How can I accomplish this in twig?
For a twig only solution you can define a custom twig function path_lang(), which adds the language object to options, if a language code is  provided as additional parameter:

src/TwigExtension.php:

&lt;?php

namespace Drupal\mymodule;

use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Routing\UrlGeneratorInterface;

class TwigExtension extends \Twig_Extension {

  protected $languageManager;

  protected $urlGenerator;

  public function __construct(LanguageManagerInterface $language_manager, UrlGeneratorInterface $url_generator) {
    $this-&gt;languageManager = $language_manager;
    $this-&gt;urlGenerator = $url_generator;
  }

  public function getName() {
    return 'mymodule';
  }

  public function getFunctions() {
    return [
      new \Twig_SimpleFunction('path_lang', [$this, 'getPathLang']),
    ];
  }

  public function getPathLang($name, $parameters = [], $options = [], $langcode = '') {
    if (!empty($langcode)) {
      if ($language = $this-&gt;languageManager-&gt;getLanguage($langcode)) {
        $options['language'] = $language;
      }
    }
    return $this-&gt;urlGenerator-&gt;generateFromRoute($name, $parameters, $options);
  }
}


mymodule.services.yml:

services:
  mymodule.twig.extension:
    arguments: ['@language_manager', '@url_generator']
    class: Drupal\mymodule\TwigExtension
    tags:
      - { name: twig.extension }


In twig:

{{  path_lang('entity.node.edit_form', {'node': nid }, {}, 'en') }}