Created
September 24, 2010 14:01
-
-
Save kwylez/595419 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// En.php | |
return array( | |
'name' => 'First Name', | |
'address' => 'Address' | |
); | |
// Es.php | |
return array ( | |
'name' => 'nombre', 'address' => 'dirección' | |
); | |
// Controller snippet | |
/** | |
* Add language to the registry | |
*/ | |
$locale = new Zend_Locale($this->_getParam('lang')); | |
Zend_Registry::set('locale', $locale); | |
// Form snippet | |
/** | |
* Instance of Zend_Locale | |
* | |
* @var Zend_Locale | |
*/ | |
protected $_locale = null; | |
/** | |
* Allowed locale regions | |
* | |
* @var array | |
*/ | |
protected $_allowedLocales = array('en', 'es'); | |
protected $_translations = null; | |
$this->addElement('note', 'quanityInstructions', array( | |
'decorators' => $this->_standardNoteDecorator, | |
'description' => "{$this->_translations->_('quanityInstructions')}" | |
)); | |
/** | |
* Prepare the form | |
* | |
* @return boolean | |
*/ | |
private function _prepare() { | |
/** | |
* Grab the browsers locale | |
*/ | |
$this->_locale = Zend_Registry::get('locale'); | |
/** | |
* If the browser is locale isn't English or Spanish then default to | |
* English | |
*/ | |
if (!$this->_checkForValidLocaleRegion($this->_locale)) { | |
$this->_locale = new Zend_Locale('en_US'); | |
} | |
$transFile = ucfirst($this->_locale->getLanguage()).'.php'; | |
$this->_translations = new Zend_Translate('array', realpath(dirname(__FILE__).'/../../Path/To/Languages/'.$transFile), $this->_locale); | |
return true; | |
} | |
/** | |
* Check to make sure that browser's locale is english or spanish. The region | |
* doesn't matter. | |
* | |
* @param Zend_Locale $zl | |
* @return boolean | |
*/ | |
private function _checkForValidLocaleRegion(Zend_Locale $zl) { | |
return in_array($zl->getLanguage(), $this->_allowedLocales) ? true : false; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment