Skip to content

Instantly share code, notes, and snippets.

@noopable
Forked from juriansluiman/Module.php
Created July 18, 2012 10:20

Revisions

  1. Jurian Sluiman revised this gist Jul 11, 2012. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions Module.php
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ class Module implements
    public function onBootstrap(Event $e)
    {
    $default = 'nl';
    $supported = array('de', 'de-DE');
    $supported = array('en', 'en-GB');
    $app = $e->getApplication();
    $headers = $app->getRequest()->getHeaders();

    @@ -20,14 +20,13 @@ public function onBootstrap(Event $e)

    // Loop through all locales, highest priority first
    foreach ($locales as $locale) {
    $match = Locale::lookup($supported, $locale);
    if ($match !== "") {
    if (!!($match = Locale::lookup($supported, $locale))) {
    // The locale is one of our supported list
    Locale::setDefault($match);
    break;
    }
    }
    if ($match === "") {
    if (!$match) {
    // Nothing from the supported list is a match
    Locale::setDefault($default);
    }
  2. Jurian Sluiman revised this gist Jul 11, 2012. 1 changed file with 17 additions and 5 deletions.
    22 changes: 17 additions & 5 deletions Module.php
    Original file line number Diff line number Diff line change
    @@ -10,15 +10,27 @@ class Module implements
    {
    public function onBootstrap(Event $e)
    {
    $default = 'en';
    $supported = array('en', 'nl');
    $default = 'nl';
    $supported = array('de', 'de-DE');
    $app = $e->getApplication();
    $headers = $app->getRequest()->getHeaders();

    if ($headers->has('Accept-Language')) {
    $header = $headers->get('Accept-Language')->getFieldValue();
    $locale = Locale::lookup($supported, $header, false, $default);
    Locale::setDefault($locale);
    $locales = $headers->get('Accept-Language')->getPrioritized();

    // Loop through all locales, highest priority first
    foreach ($locales as $locale) {
    $match = Locale::lookup($supported, $locale);
    if ($match !== "") {
    // 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);
    }
  3. Jurian Sluiman revised this gist Jul 11, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Module.php
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ public function onBootstrap(Event $e)

    if ($headers->has('Accept-Language')) {
    $header = $headers->get('Accept-Language')->getFieldValue();
    $locale = Locale::lookup($supported, $header, $default);
    $locale = Locale::lookup($supported, $header, false, $default);
    Locale::setDefault($locale);
    } else {
    Locale::setDefault($default);
  4. Jurian Sluiman revised this gist Jul 11, 2012. No changes.
  5. Jurian Sluiman revised this gist Jul 11, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Module.php
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    namespace Application;

    use Locale;
    use Zend\EventManager\EventInterface;
    use Zend\EventManager\Event;
    use Zend\ModuleManager\Feature;

    class Module implements
  6. Jurian Sluiman revised this gist Jul 11, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Module.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    <?php
    namespace Application;

    use Locale;
    use Zend\EventManager\EventInterface;
    use Zend\ModuleManager\Feature;

    class Module implements
  7. Jurian Sluiman revised this gist Jul 11, 2012. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions Module.php
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,8 @@ class Module implements
    {
    public function onBootstrap(Event $e)
    {
    $default = 'en_US';
    $supported = array('en_US', 'de_DE', 'nl_NL');
    $default = 'en';
    $supported = array('en', 'nl');
    $app = $e->getApplication();
    $headers = $app->getRequest()->getHeaders();

    @@ -19,7 +19,6 @@ public function onBootstrap(Event $e)
    Locale::setDefault($locale);
    } else {
    Locale::setDefault($default);

    }
    }
    }
  8. Jurian Sluiman revised this gist Jul 11, 2012. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions Module.php
    Original file line number Diff line number Diff line change
    @@ -14,11 +14,12 @@ public function onBootstrap(Event $e)
    $headers = $app->getRequest()->getHeaders();

    if ($headers->has('Accept-Language')) {
    Locale::setDefault($default);
    } else {
    $header = $headers->get('Accept-Language')->getFieldValue();
    $locale = Locale::lookup($supported, $header, $default);
    Locale::setDefault($locale);
    } else {
    Locale::setDefault($default);

    }
    }
    }
  9. Jurian Sluiman revised this gist Jul 11, 2012. 1 changed file with 2 additions and 5 deletions.
    7 changes: 2 additions & 5 deletions Module.php
    Original file line number Diff line number Diff line change
    @@ -10,11 +10,8 @@ public function onBootstrap(Event $e)
    {
    $default = 'en_US';
    $supported = array('en_US', 'de_DE', 'nl_NL');

    $app = $e->getApplication();
    $sm = $app->getServiceManager();

    $headers = $app->getRequest()->getHeaders();
    $app = $e->getApplication();
    $headers = $app->getRequest()->getHeaders();

    if ($headers->has('Accept-Language')) {
    Locale::setDefault($default);
  10. Jurian Sluiman revised this gist Jul 11, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Module.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php
    namespace Application;

    use Zend\ModuleManager\Feature;
  11. Jurian Sluiman created this gist Jul 11, 2012.
    26 changes: 26 additions & 0 deletions Module.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    namespace Application;

    use Zend\ModuleManager\Feature;

    class Module implements
    Feature\BootstrapListenerInterface
    {
    public function onBootstrap(Event $e)
    {
    $default = 'en_US';
    $supported = array('en_US', 'de_DE', 'nl_NL');

    $app = $e->getApplication();
    $sm = $app->getServiceManager();

    $headers = $app->getRequest()->getHeaders();

    if ($headers->has('Accept-Language')) {
    Locale::setDefault($default);
    } else {
    $header = $headers->get('Accept-Language')->getFieldValue();
    $locale = Locale::lookup($supported, $header, $default);
    Locale::setDefault($locale);
    }
    }
    }