PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Usage of automatic Locales

Zend_Locale provides three additional locales. These locales do not belong to any language or region. They are "automatic" locales which means that they have the same effect as the method getDefault() but without the negative effects like creating an instance. These "automatic" locales can be used anywhere, where also a standard locale and also the definition of a locale, its string representation, can be used. This offers simplicity for situations like working with locales which are provided by a browser.

There are three locales which have a slightly different behaviour:

  1. 'browser' - Zend_Locale should work with the information which is provided by the user's Web browser. It is published by PHP in the global variable $_SERVER['HTTP_ACCEPT_LANGUAGE'].

    If a user provides more than one locale within his browser, Zend_Locale will use the first found locale. If the user does not provide a locale or the script is being called from the command line the automatic locale 'environment' will automatically be used and returned.

  2. 'environment' - Zend_Locale should work with the information which is provided by the host server. It is published by PHP via the internal function setlocale().

    If a environment provides more than one locale, Zend_Locale will use the first found locale. If the host does not provide a locale the automatic locale 'browser' will automatically be used and returned.

  3. 'auto' - Zend_Locale should automatically detect any locale which can be worked with. It will first search for a users locale and then, if not successful, search for the host locale.

    If no locale can be detected, it will throw an exception and tell you that the automatic detection has been failed.

Example 540. Using automatic locales

<?php
// without automatic detection
//$locale = new Zend_Locale(Zend_Locale::BROWSER);
//$date = new Zend_Date($locale);

// with automatic detection
$date = new Zend_Date('auto');

Zend Framework