Allowing the User to Dynamically Switch Languages
In order to take full advantage of this feature, you need to provide the user with a way to select the desired language. This is very easily done by creating links that pass along an easily identifiable parameter and corresponding locale, like so:
http://www.beginningphpandmysql.com/toc/lang/it/To retrieve the lang = it parameter, just add the following line to the appropriate controller method: $lang = $this->_request->getParam('lang'); Then modify the Zend_Translate constructor call used earlier in this chapter to read like so:$translate = new Zend_Translate('csv', "c:apache2htdocslanguages$lang.csv", '$lang');
This approach allows the reader to choose a desired language simply by clicking on an appropriate link. Alternatively, if your users register for the site, you could provide them with the opportunity to choose a default language, storing it within a database, and subsequently retrieving that value and placing it within a session variable once the user logs in.
Where to Go From Here?
Zend_Translate is just one feature at your disposal when creating websites for the world. For instance, the Zend_Locale component greatly reduces the complexity of localizing dates, numbers, currency, and calendars. The Zend_Measure component helps you convert data such as temperature and velocity, the units of which vary widely among nations.