July 31, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Build Multi-lingual Websites With the Zend Framework

  • June 15, 2007
  • By Jason Gilmore
  • Send Email »
  • More Articles »

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.

I'd love to hear of anything you do with what was covered in this article! Please email me at the address found in the below bio!

About the Author

W. Jason Gilmore is Apress' Open Source Editorial Director, and co-founder of IT Enlightenment. He's the author of several books, including the best-selling "Beginning PHP and MySQL 5: Novice to Professional, Second Edition" (Apress, 2006. 913pp.). Jason loves receiving e-mail; so don't hesitate to write him at wjATwjgilmore.com.





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel