Skip to main content
Bumped by Community user
Reverted bad edit that abuses quote formatting, and actually fixed formatting
Source Link

I'm trying this script to detect browser language and redirect to Italian store view if the language is Italian or English store view if the language is not Italian. The country code is correctly detected but I'm not able to redirect to the store view. I've also tried using header('Location: ' . $lang), lang was 'Italian' or 'default'. It works but I don't want to have in the URL the store view code.

Here is the script:

I'm trying this script to detect browser language and redirect to Italian store view if language is Italian or English store view if language is not Italian.

The country code is correctly detected but I'm not able to redirect to the store view. I've also tried using header('Location: ' . $lang), lang was 'italian' or 'default'. It works but I don't want to have in the url the store view code.

Here is the script:

function getCountryCode(){
  $CountryCode = substr(getenv('HTTP_ACCEPT_LANGUAGE'), 0, 2);
  if ($CountryCode=='it') {
    $lang = 3;
  }
  else{ 
    $lang = 1;
 }

 return $lang;
}

$lang = getCountryCode();

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        

$objectManager->get('\Magento\Store\Model\StoreManagerInterface')-
>setCurrentStore(0);

I'm trying this script to detect browser language and redirect to Italian store view if the language is Italian or English store view if the language is not Italian. The country code is correctly detected but I'm not able to redirect to the store view. I've also tried using header('Location: ' . $lang), lang was 'Italian' or 'default'. It works but I don't want to have in the URL the store view code.

Here is the script:

function getCountryCode(){
  $CountryCode = substr(getenv('HTTP_ACCEPT_LANGUAGE'), 0, 2);
  if ($CountryCode=='it') {
    $lang = 3;
  }
  else{ 
    $lang = 1;
 }

 return $lang;
}

$lang = getCountryCode();

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        

$objectManager->get('\Magento\Store\Model\StoreManagerInterface')-
>setCurrentStore(0);

I'm trying this script to detect browser language and redirect to Italian store view if language is Italian or English store view if language is not Italian.

The country code is correctly detected but I'm not able to redirect to the store view. I've also tried using header('Location: ' . $lang), lang was 'italian' or 'default'. It works but I don't want to have in the url the store view code.

Here is the script:

function getCountryCode(){
  $CountryCode = substr(getenv('HTTP_ACCEPT_LANGUAGE'), 0, 2);
  if ($CountryCode=='it') {
    $lang = 3;
  }
  else{ 
    $lang = 1;
 }

 return $lang;
}

$lang = getCountryCode();

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        

$objectManager->get('\Magento\Store\Model\StoreManagerInterface')-
>setCurrentStore(0);
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
corrected spelling, fixed grammar, improved formatting
Source Link
Randhir Yadav
  • 2.6k
  • 1
  • 20
  • 31

I'm trying this script to detect browser language and redirect to italian store view if language is italian or english store view if language is not italian. The country code is correctly detected but I'm not able to redirect to the store view. I've also tried using header('Location: ' . $lang), lang was 'italian' or 'default'. It works but I don't want to have in the url the store view code.

Here is the script:

I'm trying this script to detect browser language and redirect to Italian store view if the language is Italian or English store view if the language is not Italian. The country code is correctly detected but I'm not able to redirect to the store view. I've also tried using header('Location: ' . $lang), lang was 'Italian' or 'default'. It works but I don't want to have in the URL the store view code.

Here is the script:

function getCountryCode(){
  $CountryCode = substr(getenv('HTTP_ACCEPT_LANGUAGE'), 0, 2);
  if ($CountryCode=='it') {
    $lang = 3;
  }
  else{ 
    $lang = 1;
 }

 return $lang;
}

$lang = getCountryCode();

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        

$objectManager->get('\Magento\Store\Model\StoreManagerInterface')-
>setCurrentStore(0);

I'm trying this script to detect browser language and redirect to italian store view if language is italian or english store view if language is not italian. The country code is correctly detected but I'm not able to redirect to the store view. I've also tried using header('Location: ' . $lang), lang was 'italian' or 'default'. It works but I don't want to have in the url the store view code.

Here is the script:

function getCountryCode(){
  $CountryCode = substr(getenv('HTTP_ACCEPT_LANGUAGE'), 0, 2);
  if ($CountryCode=='it') {
    $lang = 3;
  }
  else{ 
    $lang = 1;
 }

 return $lang;
}

$lang = getCountryCode();

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        

$objectManager->get('\Magento\Store\Model\StoreManagerInterface')-
>setCurrentStore(0);

I'm trying this script to detect browser language and redirect to Italian store view if the language is Italian or English store view if the language is not Italian. The country code is correctly detected but I'm not able to redirect to the store view. I've also tried using header('Location: ' . $lang), lang was 'Italian' or 'default'. It works but I don't want to have in the URL the store view code.

Here is the script:

function getCountryCode(){
  $CountryCode = substr(getenv('HTTP_ACCEPT_LANGUAGE'), 0, 2);
  if ($CountryCode=='it') {
    $lang = 3;
  }
  else{ 
    $lang = 1;
 }

 return $lang;
}

$lang = getCountryCode();

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        

$objectManager->get('\Magento\Store\Model\StoreManagerInterface')-
>setCurrentStore(0);