Score:0

EntityQuery to return translated version where available

cn flag

I am returning a subset of data using a preprocessor and entityQuery:

$query = \Drupal::entityQuery('node');
    $query->accessCheck(FALSE)
        ->condition('type', 'news')
        ->sort('changed', 'DESC')
        ->range(0, 9);

$nids = $query->execute();
$entities = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($nids);

Some of these articles may have translations, and I want to return or select the translated version where available. Currently it shows the main language. I already know the language code (say en-uk) in my preprocessor.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.