We need better/easier ways to detect what the current lang is.
Detect what the active selected lang
Array of supported langs on the site
check if the node has any translations
Some code from Mises I've been using in hook_preprocess_node().
$variables['#cache']['contexts'][] = 'languages:language_interface';
// TODO: Would like to to get all language variables in a helper function so it can be reused in different hooks and Entities
// Create a list of all supported languages on Mises.
$langcodes = \Drupal::languageManager()->getLanguages();
$langcodesList = array_keys($langcodes);
$variables['language']['supported_langs'] = $langcodesList;
// Default language.
$variables['language']['active'] = 'en';
if (\Drupal::languageManager()->getCurrentLanguage()->getId()) {
$variables['language']['active'] = \Drupal::languageManager()->getCurrentLanguage()->getId();
}
$translations = $node->getTranslationLanguages();
// Check to see if node has more than one translation.
$hasTranslations = count($translations) > 1;
$variables['language']['has_translations'] = FALSE;
if ($hasTranslations) {
$variables['language']['has_translations'] = TRUE;
}
We need better/easier ways to detect what the current lang is.
Some code from Mises I've been using in hook_preprocess_node().