Studyon Minte9.com
ZF 1.0

Study

Translate



#index.php
$frontController->registerPlugin(new Application_Plugin_Language());

#plugin
<?php
require_once "Zend/Controller/Plugin/Abstract.php";
class Application_Plugin_Language extends Zend_Controller_Plugin_Abstract {

	private function _initI18n() {
		
		$languages = array(1=>'ro', 2=>'en');
		
		$ns = new Zend_Session_Namespace('defaultNamespace');
		
		$frontController = Zend_Controller_Front::getInstance();
		$lang = $frontController->getRequest()->setLang;

		//if a new language is requested, use it, otherwise use default
		if (in_array($lang, $languages)) {
			$ns->lang = $lang;
		 } else {
			$lang = isset($ns->lang) && in_array($ns->lang, $languages) ? $ns->lang : _DEFAULT_LANGUAGE;
		 }

		include('../Application/translations/' . $lang . '.php');

		$adapter = new Zend_Translate('array', $translationArray, $lang);
		Zend_Registry::set('Zend_Translate', $adapter);
	}

	public function dispatchLoopStartup() {
		$this->_initI18n();
	}
}

#Application/translations/en.php
<?php
$translationArray = array(
	'YES' => 'Yes tranlation',
	'NO' => 'No tranlation',

	'isEmpty' => 'Valoare necompletata', // #Zend_Validate_NotEmpty (const IS_EMPTY = 'isEmpty')
);

#view
<?php 
	echo $this->translate('YES');
	// display 'Yes tranlation'


http://framework.zend.com/manual/en/zend.translate.using.html
http://stackoverflow.com/questions/307273/where-to-use-zend-framework-translation-tool

http://perevodik.net/en/posts/10/

http://webcache.googleusercontent.com/search?q=cache:mfAg-4P2uMkJ