0

Good afternoon. A question arose as follows: a few blocks are displayed on the page.
A material type has been created for each. The site has multilingualism. Those. in the admin panel, you can translate any of the nodes. These blocks are displayed in this way:


namespace Drupal\text_imgs\Plugin\Block;
use Drupal\Core\Block\BlockBase;
class TextImgsBlock extends BlockBase
{
    public function build()
    {
        $query = \Drupal::entityQuery('node')
            ->condition('type', 'text_imgs')
            ->condition('status', NODE_PUBLISHED)
            ->sort('field_sort', 'ASC')
            ->range(0,6);

        $nodeIds = $query->execute();

        $items = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($nodeIds);

        return array(
            '#theme' => 'text-imgs',
            '#data' => array(
                'items' => $items
            ),
        );
    }
}

Now only the part of the text that directly relates to the current page is translated accordingly. Blocks added in this way are not translated. Tell me how to do this? Thanks.

  • I determine the current language $language = \Drupal::languageManager()->getCurrentLanguage()->getId(); I don’t understand what needs to be added to the returned array '#langcode' => $language->getId(), – alex.bo Feb 13 at 12:33

Browse other questions tagged or ask your own question.