Peter,

Add a translator when you want to translate the returned messages.

According to your example:
$adapter->setTranslator(Instance_Of_Zend_Translate);

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message ----- From: "Peter Wansch" <[email protected]>
To: <[email protected]>
Sent: Thursday, May 14, 2009 3:16 PM
Subject: [fw-general] Application-provided messages for Zend_File?



Hi,
We're using Zend_File to upload images and it works very well. We display
messages as recommended in the ZF documentation:

               $messages = $adapter->getMessages();
           throw new GgvException($e->getMessage());

However, we'd like to have control over some of these messages and translate
them using our own strings. Is there a way instead of getMessages to
retrieve meaningful codes so that we can provide our own messages?

Thanks,
Peter



      // Uploading an image file
       $adapter = new Zend_File_Transfer_Adapter_Http();

// Limit the extensions to jpg files of a certain size and dimension
       $adapter->addValidator('Extension', false, array('jpg,gif,png',
true))
             // TODO: Currently MimeType validator is not working need to
take a look on it
              // ->addValidator('MimeType', false, array('image/gif',
'image/jpeg', 'image/png'))
               ->addValidator('Size', false,
$this->_config->userimages->maxsize)
               ->addValidator('FilesSize', false,
$this->_config->userimages->maxsize)
               ->addValidator('Count', false, 1)
               ->addValidator('ImageSize', false,
array($this->_config->userimages->minheight,
$this->_config->userimages->minwidth, $this->_config->userimages->maxheight,
$this->_config->userimages->maxwidth))
               ->setDestination(GOGOVERDE_PATH_ROOT . $destination);


      // Returns all known internal file information
      $files = $adapter->getFileInfo();

      foreach ($files as $file => $info)
      {
           // file uploaded ?
           if (!$adapter->isUploaded($file))
           {
                throw new GgvException($this->view->translate('No image
file selected for upload.'));
           }
      }


      if (!$adapter->isValid())
       {
               $messages = $adapter->getMessages();
               throw new GgvException(implode('\n', $messages));
       }


        // Get image info
       $imageInfo = $adapter->getFileInfo($imageVariableName);

       // Retrieve image Name
       $imageName =  $imageInfo[$imageVariableName]['name'];

       // Get image type
       $imageType = end(explode('.', $imageName));


       try
       {
           // Receive the uploaded file
           if (!$adapter->receive())
           {
               $messages = $adapter->getMessages();
               throw new GgvException(implode('\n', $messages));
           }
       }
       catch (Zend_File_Transfer_Exception $e)
       {
           throw new GgvException($e->getMessage());
       }


--
View this message in context: http://www.nabble.com/Application-provided-messages-for-Zend_File--tp23540417p23540417.html Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to