Skip to content

Instantly share code, notes, and snippets.

@kwylez
Created September 24, 2010 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwylez/595419 to your computer and use it in GitHub Desktop.
Save kwylez/595419 to your computer and use it in GitHub Desktop.
<?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