-
-
Save xelaz/8f59af81964e09a2bc8b to your computer and use it in GitHub Desktop.
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 | |
namespace Application; | |
use Locale; | |
use Zend\EventManager\Event; | |
use Zend\ModuleManager\Feature; | |
class Module implements | |
Feature\BootstrapListenerInterface | |
{ | |
public function onBootstrap(Event $e) | |
{ | |
$default = 'nl'; | |
$supported = array('en', 'en-GB'); | |
$app = $e->getApplication(); | |
$headers = $app->getRequest()->getHeaders(); | |
if ($headers->has('Accept-Language')) { | |
$locales = $headers->get('Accept-Language')->getPrioritized(); | |
// Loop through all locales, highest priority first | |
foreach ($locales as $locale) { | |
if (!!($match = Locale::lookup($supported, $locale))) { | |
// The locale is one of our supported list | |
Locale::setDefault($match); | |
break; | |
} | |
} | |
if (!$match) { | |
// Nothing from the supported list is a match | |
Locale::setDefault($default); | |
} | |
} else { | |
Locale::setDefault($default); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment