* @package wombat * @subpackage nls */ /** * patI18n Module CheckConfig * * Check locale settings against config * * @version 1.0.1 * @package wombat */ class patI18n_Module_CheckConfig extends patI18n_Module { /** * current config * * Options: lanauges * - default language * - available locale strings (five letter codes) * * @var array */ protected $conf = array( 'languages' => array( 'default' => 'C', 'available' => array() ) ); /** * Switch to language * * Check available languages in configuration. If no matching * * @param string $string * @return booll true on success */ public function setLocale(&$locale) { // locale not configured $available = array(); if (is_array($this->conf['languages']['available'])) { $available = $this->conf['languages']['available']; } if (!isset($this->conf['languages']['default']) || empty($this->conf['languages']['default'])) { $args = array( 'msg' => 'Default language is not configured!', 'code' => 1, 'class' => __CLASS__, ); throw WBClass::create('WBException_Config', $args); return false; } // check locale for available languages if (in_array($locale, $available)) { return true; } if (2 < strlen($locale)) { $locale = $this->conf['languages']['default']; return true; } // two letter codes? $locale = substr($locale, 0, 2); foreach ($available as $lang) { if (substr($lang, 0, 2) == $locale) { $locale = $lang; return true; } } $locale = $this->conf['languages']['default']; return true; } }