Is there any way to redirect page to front page, if it isn't translated? Is there any way to redirect page to homepage if its translated page not found.

Suppose my page url is /en/node/237, If I switch translation from English to German /ge/node/237, if it's translated page not found, URL should redirect to homepage of its native language like: /ge/home 

Here is my code:

 use \Drupal\node\Entity\Node;

   $elements = [];
 $ids = \Drupal::entityQuery('node')
  -&gt;condition('type', 'intro_2')
  -&gt;condition('langcode', 'fr')
  -&gt;condition('nid',1218)
  -&gt;execute();

 $nodes = Node::loadMultiple($ids);
  $language = 'fr';

 foreach ($nodes as $node) {
 $translation = $node-&gt;getTranslation($language);
$elements[] = [
 'node' =&gt;$translation-&gt;nid-&gt;value,
'title' =&gt; $translation-&gt;title-&gt;value,
'url' =&gt; $translation-&gt;url(),
];
  }
dpm($elements);


Above code working fine i have checked on /devel/php,but i am having only following issues:

1)How to get current page node type dynamically in database query

2)How to get current page language dynamically in database query

3)How to get current page node dynamically in database query

Can anyone modify the above code?
To get current node:

$node = \Drupal::routeMatch()-&gt;getParameter('node');
if ($node) {
  $node_type = $node-&gt;getType();
}


Current language:

$language = \Drupal::languageManager()-&gt;getCurrentLanguage();
$langcode = $language-&gt;getId();
$language_name = $language-&gt;getName();


Check if translation is not available and redirect:

use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\RedirectResponse;

$translation = $node-&gt;getTranslation($langcode);
if (!$translation) {
  $url = Url::fromRoute('&lt;front&gt;', [], ['language' =&gt; $language]);
  $response = new RedirectResponse($url-&gt;toString());
  $response-&gt;send();
}


P.S.: I believe entity query you posted is a simplified version of smth more complex in your logic. Otherwise I see no reason to pass node id to entity query condition to get it back eventually. If you always have just one node use Node::load($id) instead of Node::loadMultiple($ids), and you don't need foreach in this case.