Last active
March 27, 2019 15:04
-
-
Save paulund/5894287 to your computer and use it in GitHub Desktop.
Automatically Detect Browser Language With PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$supportedLangs = array('en-GB', 'fr', 'de'); | |
$languages = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']); | |
foreach($languages as $lang) | |
{ | |
if(in_array($lang, $supportedLangs)) | |
{ | |
// Set the page locale to the first supported language found | |
$page->setLocale($lang); | |
break; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Detect browser language | |
$_SERVER['HTTP_ACCEPT_LANGUAGE']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately this won't find a match if
$_SERVER['HTTP_ACCEPT_LANGUAGE'] == 'en'
.