How to translate a node in a custom block? I know that the question has been asked several time but I didn't find how to get the translation of a node entity.

Here is the code : 

    $countries = \Drupal::entityTypeManager()
        -&gt;getStorage('node')
        -&gt;loadByProperties($properties);

    return [
      '#theme' =&gt; 'country_selector_block',
      '#langcode' =&gt; $lang-&gt;getId(),
      '#countries' =&gt; $countries,
    ];


And in the twig template I put : 

{% for country in countries %}
    &lt;option value="{{ country.field_code.value }}"&gt;{{ country.title.value|t }}&lt;/option&gt;
{% endfor %}


=> but it return the country name in the default language

Can you explain how to handle that ?
You need to pass the loaded nodes/countries through the following so that Drupal marks the best available translation as active, then do not use t() in the template. That is a security risk, you must never pass user input to t().

$country = \Drupal::service('entity.repository')-&gt;getTranslationFromContext($country).


Do that in a loop on $countries for example, or use array_walk()/array_map().