예제 #1
0
  function process() {
    parent::process();
    
    if(!$this->available) {
      $this->getDocument()->setVariable('notAvailable', true);
      return;
    }
    
    // Prepare the document
    $r = $this->getResponce();
    $rq = $this->getRequest();
    $d = $this->getDocument();
    $d->setVariable('form', $this->form);
    
    try {
      // If the form was submitted...
      if($this->form->isValidSubmission()) {
        // See if the dialect and collation have been selected
        @list($lc, $dc, $collc) = split('_', $rq->getParameter('dialect'));
      
        // Get the selected country code
        $cc = $this->getRequest()->getParameter('country', 'US') or $cc = null;
      
        // Instantiate the locale
        $l = I18N::getLocale($cc, $lc, $dc);
      
        // See if the time zone has been selected
        if($tz = $this->getRequest()->getParameter('tz')) {
          $l->setTimeZone(I18N::getTimeZone($tz));
        }
      } else {
        // the form has not been submitted, get the default locale
        $l = I18N::getLocale();
        $collc = 'Default';
      }
      
      $this->dialect = $l->getDialect();
      $this->collation = $this->dialect->getCollation($collc ? $collc :  'Default');
      $this->caseSensitive = $rq->getParameter('caseSensitive');
      
      // Load the message dictionary
      $mf = new I18NMessageFile($this->getPackage()->getResourcePath('messages'));
      
      // Collate some words in the selected dialect and coolation
      $coll = explode(',', $mf->translateMessage('words', $this->dialect->getLanguage()->getCode()));
      usort($coll, array($this, 'langSort'));
      $d->setVariable('coll', (join(', ', $coll)));
    } catch(I18NException $e) {
      // Smth went wrong
      $d->setVariable('error', $e->getMessage());
      $l = I18N::getLocale();
      $collc = 'Default';
    }
    
    $d->setLocale($l);
    
    // Set some info
    $c = $l->getCountry();
    $d->setVariable('cc', $c->getCode());
    $d->setVariable('cn', $c->getName());
    $d->setVariable('cdc', $c->getDialCode());
    $d->setVariable('ccc', $l->getCurrencyCode());
    $d->setVariable('ccs', $l->getCurrencySymbol());
    $dial = $l->getDialect();
    $d->setVariable('lc', $dial->getLanguage()->getCode());
    $d->setVariable('dc', $dial->getCode());
    $d->setVariable('dn', $dial->getName());    
    $col = $l->getDialect()->getCollation($collc ? $collc :  'Default');
    $d->setVariable('collc', $col->getCode());
    $d->setVariable('colln', $col->getName());
    $tz = $l->getTimeZone();
    $d->setVariable('tzl', join(', ', $tz->getLocations()));
    $d->setVariable('tzo', $tz->formatOffset($tz->getUTCOffset()));
    $d->setVariable('tza', $tz->getStandardAbbrev());
    $d->setVariable('tzco', $tz->formatOffset($tz->getCurrentOffset()));
    $d->setVariable('tzca', $tz->getCurrentAbbrev());
    $d->setVariable('tzt', $tz->isDSTEnabled() ? 'yes' : 'no');
    $d->setVariable('tzs', $tz->isSummerTime() ? 'yes' : 'no');

    $l->setMessageDictionary($mf);
  }
예제 #2
0
 /**
  * Returns a long formatted date from timezone.
  * Supported locales: en_US, en_GB, es_ES, de_DE
  *
  * @since   0.0.1
  *
  * @access  public
  * @static
  * @param   mixed   $date   Optional. Timestamp or formatted date time. Default: null
  * @return  string  Formatted date.
  */
 public static function getLongDate($date = null)
 {
     $timestamp = self::getTimestampFromFormat($date);
     $locale = I18N::getLocale();
     $output = null;
     switch ($locale) {
         case 'en_US':
         case 'en_GB':
             $output = strftime('%B, ', $timestamp) . trim(self::getOrdinalNumber(strftime('%e', $timestamp))) . strftime(' %Y', $timestamp);
             break;
         case 'es_ES':
             $output = strftime('%A ', $timestamp) . trim(strftime('%e', $timestamp)) . strftime(' de %B de %Y', $timestamp);
             break;
         default:
             $output = strftime('%A, ', $timestamp) . trim(strftime('%e.', $timestamp)) . strftime(' %B %Y', $timestamp);
             break;
     }
     return $output;
 }