Trying to display or render values from links field within paragraph field base on its current language I'm currently using Drupal 8 Paragraph and I'm trying to figure out how I can display or output the url and title of a link field from within a Paragraph base on the current language via preprocess. Here is a snippet of the code I'm working on.

function iom_preprocess_paragraph(&amp;$variables) {

    $language = \Drupal::languageManager()-&gt;getCurrentLanguage();
    $variables['lang_code'] = $language-&gt;getId();
}




function _generatePrimaryLinkElement($currentNode, $entity, $title, $url) {

    $attributes = new Attribute(['class' =&gt; ['menu-item']]);

    if ($entity &amp;&amp; ($currentNode-&gt;id() === $entity-&gt;id())) {
        $attributes['class'][] = '-active';
    }

    return [
        'attributes' =&gt; $attributes,
        'link' =&gt; [
            'attributes' =&gt; new Attribute([
                'href' =&gt; $url,
                'class' =&gt; ['link']
            ])
        ],
        'title' =&gt; $title
    ];
}




function _preprocess_primary_links_paragraph($paragraph, &amp;$variables) {
    // Current page node
    $currentNode = \Drupal::request()-&gt;attributes-&gt;get('node');
    $activeLanguage = \Drupal::languageManager()-&gt;getCurrentLanguage()-&gt;getId();
    $links = [];

    foreach ($paragraph-&gt;field_link as $link) {
        $entity = _loadEntityByUri($link-&gt;uri);

        $title = $link-&gt;title;

        // If there is an entity and the title is not set of the link
        // use the entity title instead
        if ($entity &amp;&amp; !$title) {
            $title = $entity-&gt;title-&gt;value;
        }

        $links[] = _generatePrimaryLinkElement($currentNode, $entity, $title, $link-&gt;getUrl()-&gt;toString());
    }

    $variables['label'] = $paragraph-&gt;field_label-&gt;value;
    $variables['links'] = $links;
}




&lt;div class="sidebar-menu-group primary-link"&gt;
    &lt;span class="label"&gt;{{ label }}&lt;/span&gt;
    &lt;ul class="menu -sidebar"&gt;


        {% for link in links %}

            &lt;li {{link.attributes}}&gt;
                &lt;a {{link.link.attributes}}&gt;{{link.title}}&lt;/a&gt;
            &lt;/li&gt;
        {% endfor %}
    &lt;/ul&gt;
&lt;/div&gt;
Below is some general purpose code I wrote to solve this problem across a lot of code.  It can take either a standard /node/## path or an alias and convert it to the desired language.  It assumes you are using prefixed language URLs and 'en' is the default language. If FL URL can not be found, the same URL is returned.

/**
 * Utility function to take a standard drupal path or alias and convert to the specified language alias path.
 *
 * @param string $path Root relative standard path, e.g. /node/### or english alias, e.g. /my/view and the like.
 * @param string $langCode  Language code for the resulting url. If not specified current language is used.
 * @param boolean $testPrefix If true, the input URL will be tested to see if the language prefix is already there.
 * @return string
 */
function my_i18n_language_url( $path, $langCode=NULL, $testPrefix=FALSE ) {
  if ( empty($langCode) ) {
    $langCode = \Drupal::languageManager()-&gt;getCurrentLanguage()-&gt;getId();
  }
  // Optional check to see if url already has language prefix.
  if ( $testPrefix ) {
    $languages = \Drupal::languageManager()-&gt;getLanguages();
    foreach ( $languages as $code =&gt; $lang ) {
      if ( strpos($path, "/{$code}/") === 0 ) {
        return $path;
      }
    }
  }
  // If in alias format convert to node/### format.
  if ( strpos($path, "/node/") !== 0 ) {
    $url = \Drupal::service('path.alias_manager')-&gt;getPathByAlias($path,'en');
    if ( $url == $path ) {
      // Maybe it's a view
      try {
        $url = \Drupal::service('path.alias_manager')-&gt;getAliasByPath($path, $langCode);
        if ( $url == $path ) {
          return $path;
        }
      }
      catch ( Exception $e ) {
        watchdog_exception('my_i18n', $e );
        return $path;
      }
    }
    $path = $url;
  }
  $url = $path;
  try {
     $url = \Drupal::service('path.alias_manager')-&gt;getAliasByPath($path, $langCode);
  }
  catch ( Exception $e ) {
    watchdog_exception('my_i18n', $e );
    return $path;
  }
  $url = my_i18n_language_prefix($langCode) . $url;
  return $url;
}

/**
 * Utility function to get a language prefix based on the current page language.
 *
 * @param string $langCode  Optional - defaults to current language
 * @return string
 */
function my_i18n_language_prefix( $langCode=NULL) {
  $manager =  \Drupal::languageManager();
  $default_lang = $manager-&gt;getDefaultLanguage()-&gt;getId();
  if ( empty($langCode) ) {
    $langCode = $manager-&gt;getCurrentLanguage()-&gt;getId();
  }
  if ( $langCode == $default_lang ) {
    return "";
  }
  return "/{$langCode}";
}