* @package wombat * @subpackage nls */ /** * patI18n Module CheckConfig * * Check locale settings against config * * @version 1.0.0 * @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 if (!isset($this->conf['languages']['available']) || empty($this->conf['languages']['available'])) { $args = array( 'msg' => 'There are not available languages configured!', 'code' => 1, 'class' => __CLASS__, ); throw WBClass::create('WBException_Config', $args); return false; } 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, $this->conf['languages']['available'])) { return true; } if (2 < strlen($locale)) { $locale = $this->conf['languages']['default']; return true; } // two letter codes? $locale = substr($locale, 0, 2); foreach ($this->conf['languages']['available'] as $lang) { if (substr($lang, 0, 2) == $locale) { $locale = $lang; return true; } } $locale = $this->conf['languages']['default']; return true; } }