In multi-lingual web pages are more and more important, I would like to show two ways how to static text snippets from your application with Zend Framework. Zend Framework provides us with several packages as Zend_Translate Zend_Locale and developers to make life easier – but how these components work together?

Creating a Zend Framework application
First, we need a Zend Framework application. You can use either your own existing or create a new one directly with Zend Studio for Eclipse:
If you do not know what a Zend Framework application you can take a look at the Zend Framework QuickStart.

Zend_Locale and Zend_Translate
As already mentioned, we have instances of Zend_Locale and Zend_Translate. I initialized both objects in the class initializer which is created by the Zend Framework Project Wizard:



* Initialize Locale and Translation


* @return void


public function initLocale() {

$localeValue = ‘en’;

$locale = new Zend_Locale($localeValue);

Zend_Registry::set(’Zend_Locale’, $locale);

$translationFile = $this->_root . DIRECTORY_SEPARATOR . ‘lang’

. DIRECTORY_SEPARATOR . $localeValue . ‘.inc.php’;

$translate = new Zend_Translate(’array’, $translationFile, $localeValue);

Zend_Registry::set(’Zend_Translate’, $translate);


The Initializer:: initLocale ()-method is used by the Initializer:: _routeStartup ()-method. Obviously you can use this functionality in a similar way also in the bootstrap file.
I have chosen the very simple way of initializing a Zend_Locale object for this demo: I have the variable $ localeValue directly into the method. Of course, this is not recommended! Maybe you can use the current user of the meeting locale or let Zend_Locale choose. Once you Zend_Locale object, you can use the complete application documents, by the Zend_Registry with key “Zend_Locale. So it is possible to have several IF components to find it there. In the next step we create the necessary components for translation. Therefore, we use the array Zend_Translate and adapters. That means we have to create a PHP file provides a translation of the array.

  1. 2 Trackback(s)

  2. Jun 29, 2010: WAYNE
  3. Mar 9, 2014: Derrick

Post a Comment