The simplest usecase within an application is to use the clients locale. When you create
a instance of
Zend_Currency without giving any options, your
clients locale will be used to set the proper currency.
Example 158. Creating a currency with client settings
Let's assume that your client has set "en_US" as wished language within his browser.
In this case
Zend_Currency will automatically detect the
currency which has to be used.
$currency = new Zend_Currency();
// See the default settings which are depending on the client
The created object would now contain the currency "US Dollar" as this is the actual assigned currency for US (United States). It has also other options set, like "$" for the currency sign or "USD" for the abbreviation.
Automatic locale detection does not always work
You should note that this automatic locale detection does not always work properly.
The reason for this behaviour is that
Zend_Currency must have
a locale which includes a region. When the client would only set "en" as locale
Zend_Currency would not know which of the more than 30
countries was meant. In this case an exception would be raised.
A client could also omit the locale settings within his browser. This would lead to the problem that your environment settings will be used as fallback and could also lead to an exception.