protected function createMessageTemplate($catalogue)
 {
     if (null === $catalogue) {
         $catalogue = 'messages';
     }
     $variants = $this->getCatalogueList($catalogue);
     $variant = array_shift($variants);
     $mo_file = $this->getSource($variant);
     $po_file = $this->getPOFile($mo_file);
     $dir = dirname($mo_file);
     if (!is_dir($dir)) {
         @mkdir($dir);
         @chmod($dir, 0777);
     }
     if (!is_dir($dir)) {
         throw new sfException(sprintf("Unable to create directory %s.", $dir));
     }
     $po = TGettext::factory('PO', $po_file);
     $result['meta']['PO-Revision-Date'] = date('Y-m-d H:i:s');
     $result['strings'] = array();
     $po->fromArray($result);
     $mo = $po->toMO();
     if ($po->save() && $mo->save($mo_file)) {
         return array($variant, $mo_file, $po_file);
     } else {
         throw new sfException(sprintf("Unable to create file %s and %s.", $po_file, $mo_file));
     }
 }
 /**
  * Updates the translation.
  *
  * @param string the source string.
  * @param string the new translation string.
  * @param string comments
  * @param string the catalogue of the translation.
  * @return boolean true if translation was updated, false otherwise.
  */
 function update($text, $target, $comments, $catalogue = 'messages')
 {
     $variants = $this->getVariants($catalogue);
     if ($variants) {
         list($variant, $MOFile, $POFile) = $variants;
     } else {
         return false;
     }
     if (is_writable($MOFile) == false) {
         throw new sfException(sprintf("Unable to update file %s, file must be writable.", $MOFile));
     }
     if (is_writable($POFile) == false) {
         throw new sfException(sprintf("Unable to update file %s, file must be writable.", $POFile));
     }
     $po = TGettext::factory('PO', $POFile);
     $po->load();
     $result = $po->toArray();
     foreach ($result['strings'] as $string => $value) {
         if ($string == $text) {
             $result['strings'][$string] = $target;
             $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
             $po->fromArray($result);
             $mo = $po->toMO();
             if ($po->save() && $mo->save($MOFile)) {
                 if (!empty($this->cache)) {
                     $this->cache->clean($variant, $this->culture);
                 }
                 return true;
             } else {
                 return false;
             }
         }
     }
     return false;
 }