Drupal - How can I get my module to see the current language my user is using?

You could try the following:

$lang_code = \Drupal::languageManager()->getCurrentLanguage()->getId();
Node::load(10)->getTranslation($lang_code)->toArray();

Good luck!


UPDATED ANSWER:

<?php
use Drupal\Core\Language\LanguageInterface;
use Drupal\node\Entity\Node;
$node = Node::load(10);
$langcode = \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT);
$translation = $node->getTranslation($langcode);
// Now deal with the right language from here on.
?>

Hope this works!

Tags:

8

I18N L10N