/**
  * gets the correct string, for a given language.
  *   if it can't get the correct language, it will try to gets the string
  *   from the default language.
  *   if both fails, it will raise a fatal_error.
  */
 function get($key, $args = null, $locale = null)
 {
     $me =& CopixI18N::instance();
     //finds out required lang / coutry
     if ($locale === null) {
         $plug =& $GLOBALS['COPIX']['COORD']->getPlugin('i18n');
         if ($plug === null) {
             $lang = $GLOBALS['COPIX']['CONFIG']->default_language;
             $country = $GLOBALS['COPIX']['CONFIG']->default_country;
         } else {
             $lang = $plug->getLang();
             $country = $plug->getCountry();
         }
     } else {
         $ext = explode('_', $locale);
         if (count($ext) > 1) {
             $lang = $ext[0];
             $country = $ext[1];
         } else {
             $lang = $ext[0];
             $country = $ext[0];
         }
     }
     //Gets the bundle for the given language.
     $trans =& CopixSelectorFactory::create($key);
     if (!$trans->isValid) {
         trigger_error(CopixI18N::get('copix:copix.error.i18n.keyNotExists', $key), E_USER_ERROR);
     }
     $messageId = $trans->fileName;
     $trans->fileName = substr($trans->fileName, 0, strpos($trans->fileName, '.'));
     $bundle =& $me->getBundle($trans, $lang);
     //try to get the message from the bundle.
     $string = $bundle->get($messageId, $country);
     if ($string === null) {
         //if the message was not found, we're gonna
         //use the default language and country.
         if ($lang == $GLOBALS['COPIX']['CONFIG']->default_language && $country == $GLOBALS['COPIX']['CONFIG']->default_country) {
             if ($key == 'copix:copix.error.i18n.keyNotExists') {
                 $msg = 'Can\'t find message key (which should actually be THIS message): ' . $key;
             } else {
                 $msg = CopixI18N::get('copix:copix.error.i18n.keyNotExists', $key);
             }
             trigger_error($msg, E_USER_ERROR);
         }
         return $me->get($key, $args, $GLOBALS['COPIX']['CONFIG']->default_language . '_' . $GLOBALS['COPIX']['CONFIG']->default_country);
     } else {
         //here, we know the message
         if ($args !== null) {
             $string = call_user_func_array('sprintf', array_merge($string, $args));
             /*
             //            if(is_array($args)){
                            switch(count($args)){
                               case 1: $string=sprintf($string,$args[0]); break;
                               case 2: $string=sprintf($string,$args[0],$args[1]); break;
                               case 3: $string=sprintf($string,$args[0],$args[1],$args[2]); break;
                            }
             //            }else
             //               $string=sprintf($string,$args);
             */
         }
         return $string;
     }
 }
 /**
  * gets the correct string, for a given language.
  *   if it can't get the correct language, it will try to gets the string
  *   from the default language.
  *   if both fails, it will raise a fatal_error.
  */
 function get($key, $args = null, $locale = null)
 {
     $me =& CopixI18N::instance();
     //finds out required lang / coutry
     if ($locale === null) {
         $lang = $GLOBALS['COPIX']['CONFIG']->default_language;
         // rempli par le plugin egalement
         $country = $GLOBALS['COPIX']['CONFIG']->default_country;
     } else {
         $ext = explode('_', $locale);
         if (count($ext) > 1) {
             $lang = $ext[0];
             $country = $ext[1];
         } else {
             $lang = $ext[0];
             $country = $ext[0];
         }
     }
     //Gets the bundle for the given language.
     $keySelector = substr($key, 0, strpos($key, '.'));
     $trans =& CopixSelectorFactory::create($keySelector);
     if (!$trans->isValid) {
         trigger_error(CopixI18N::get('copix:copix.error.i18n.keyNotExists', $key), E_USER_ERROR);
     }
     $key = $me->_extractMessageKey($key);
     $bundle =& $me->getBundle($trans, $lang);
     //try to get the message from the bundle.
     $string = $bundle->get($key, $country);
     if ($string === null) {
         //if the message was not found, we're gonna
         //use the default language and country.
         if ($lang == $GLOBALS['COPIX']['CONFIG']->default_language && $country == $GLOBALS['COPIX']['CONFIG']->default_country) {
             if ($key == 'copix:copix.error.i18n.keyNotExists') {
                 $msg = 'Can\'t find message key (which should actually be THIS message): ' . $key;
             } else {
                 $msg = CopixI18N::get('copix:copix.error.i18n.keyNotExists', $key);
             }
             trigger_error($msg, E_USER_ERROR);
         }
         return $me->get($key, $args, $GLOBALS['COPIX']['CONFIG']->default_language . '_' . $GLOBALS['COPIX']['CONFIG']->default_country);
     } else {
         //here, we know the message
         if ($args !== null) {
             $string = call_user_func_array('sprintf', array_merge($string, $args));
         }
         return $string;
     }
 }