Source for file phpgettext.message.php

Documentation is available at phpgettext.message.php

  1. <?php
  2. /**
  3.  * @version        0.9
  4.  * @author      Carlos Souza
  5.  * @copyright   Copyright (c) 2005 Carlos Souza <csouza@web-sense.net>
  6.  * @package     PHPGettext
  7.  * @license        MIT License (http://www.opensource.org/licenses/mit-license.php)
  8.  * @link        http://phpgettext.web-sense.net
  9.  * 
  10.  * 
  11.  */
  12. defined'_VALID_MOS' or die'Direct Access to this location is not allowed.' );
  13.  
  14. {
  15.     // --- ATTRIBUTES ---
  16.     /**
  17.      * Short description of attribute comments
  18.      *
  19.      * @access public
  20.      * @var int 
  21.      */
  22.     var $comments = array();
  23.  
  24.     /**
  25.      * Short description of attribute is_fuzzy
  26.      *
  27.      * @access public
  28.      * @var int 
  29.      */
  30.     var $is_fuzzy = false;
  31.  
  32.     /**
  33.      * Short description of attribute msgid
  34.      *
  35.      * @access public
  36.      * @var int 
  37.      */
  38.     var $msgid = '';
  39.  
  40.     /**
  41.      * Short description of attribute msgid
  42.      *
  43.      * @access public
  44.      * @var int 
  45.      */
  46.     var $msgid_plural = '';
  47.  
  48.     /**
  49.      * Short description of attribute msgstr
  50.      *
  51.      * @access public
  52.      * @var int 
  53.      */
  54.     var $msgstr = '';
  55.  
  56.     // --- OPERATIONS ---
  57.  
  58.     /**
  59.      * Short description of method PHPGettext_Catalog_Entry
  60.      *
  61.      * @access public
  62.      * @author firstname and lastname of author, <author@example.org>
  63.      * @param void 
  64.      * @param void 
  65.      * @return void 
  66.      */
  67.     function PHPGettext_Message($msgid ""$msgid_plural null)
  68.     {
  69.         $this->msgid = $msgid;
  70.         $this->msgid_plural =  $msgid_plural;
  71.     }
  72.  
  73.     /**
  74.      * Short description of method setmsgstr
  75.      *
  76.      * @access public
  77.      * @author firstname and lastname of author, <author@example.org>
  78.      * @param void 
  79.      * @return void 
  80.      */
  81.     function setmsgstr($msgstr)
  82.     {        
  83.         $this->msgstr = $msgstr;
  84.         if (is_array($msgstr&& count($msgstr== 1$this->msgstr = $msgstr[0];
  85.     }
  86.  
  87.     /**
  88.      * Short description of method setFuzzy
  89.      *
  90.      * @access public
  91.      * @author firstname and lastname of author, <author@example.org>
  92.      * @param void 
  93.      * @return void 
  94.      */
  95.     function setfuzzy($is_fuzzy true)
  96.     {
  97.         $this->is_fuzzy = ($is_fuzzytrue false;
  98.     }
  99.  
  100.     /**
  101.      * Short description of method setComments
  102.      *
  103.      * @access public
  104.      * @author firstname and lastname of author, <author@example.org>
  105.      * @param void 
  106.      * @return void 
  107.      */
  108.     function setcomments($comments)
  109.     {
  110.         if (is_array($comments))
  111.         return $this->comments = $comments;
  112.  
  113.         return false;
  114.     }
  115.  
  116.     /**
  117.      * Short description of method reset
  118.      *
  119.      * @access public
  120.      * @author firstname and lastname of author, <author@example.org>
  121.      * @param void 
  122.      * @return void 
  123.      */
  124.     function reset($property 'all')
  125.     {
  126.         switch ($property)
  127.         {
  128.             case 'comments':
  129.             unset($this->comments);
  130.             break;
  131.             case 'is_fuzzy':
  132.             unset($this->fuzzy);
  133.             break;
  134.             case 'msgid':
  135.             unset($this->msgid);
  136.             break;
  137.             case 'msgstr':
  138.             unset($this->msgstr);
  139.             break;
  140.             case 'all':
  141.             default:
  142.             unset($this->comments);
  143.             unset($this->is_fuzzy);
  144.             unset($this->msgid);
  145.             unset($this->msgstr);
  146.             break;
  147.         }
  148.     }
  149.  
  150.  
  151.     /**
  152.      * Short description of method toString
  153.      *
  154.      * @access public
  155.      * @author firstname and lastname of author, <author@example.org>
  156.      * @return void 
  157.      */
  158.     function toString()
  159.     {
  160.         $string '';
  161.         // comments
  162.         if (count($this->comments > 0)) {
  163.             foreach ($this->comments as $comment){
  164.                 if (!preg_match('/^#,/'$comment&& !is_null($comment)) {
  165.                     $string .= trim($comment)."\n";
  166.                 elseif (strncmp($comment"#:"2)   == 0{
  167.                     $string .= trim($comment)."\n";
  168.                 else {
  169.                     continue;
  170.                 }
  171.             }
  172.         }
  173.         
  174.         // fuzzy entries
  175.         if ($this->is_fuzzy{
  176.             $string .= "#, fuzzy\n";
  177.         }
  178.         /*
  179.         
  180.         if (strlen($msgid) > 76) {
  181.         $entry .= 'msgid ""'."\n";
  182.         $entry .= '"'.wordwrap($msgid, 76, " \"\n\"")."\"\n";
  183.         } else {
  184.         $entry .= 'msgid "'.$msgid.'"'."\n";
  185.         }
  186.         */
  187.         // msgid
  188.         if (strpos($this->msgid"\n"0{
  189.             $string .= "msgid \"\"\n";
  190.             $msgid explode("\n"$this->msgid);
  191.             foreach ($msgid as $line)
  192.                 $string .= "\"$line\\n\"\n";
  193.         else {
  194.             $string .= "msgid \"$this->msgid\"\n";
  195.         }
  196.         
  197.         if (!empty($this->msgid_plural)) {
  198.             $string .= "msgid_plural \"$this->msgid_plural\"\n";    
  199.         
  200.         // msgstr
  201.         if (!is_array($this->msgstr&& strpos($this->msgstr"\n"0{
  202.             $string .= "msgstr \"\"\n";
  203.             $msgstr explode("\n"$this->msgstr);
  204.             foreach ($msgstr as $line)
  205.                 $string .= "\"$line\\n\"\n";
  206.             $string .= "\n";
  207.         }  // plurals
  208.         elseif (is_array($this->msgstr)){            
  209.             foreach ($this->msgstr as $k => $msgstr{
  210.                 $string .= "msgstr[$k] \"$msgstr\"\n";
  211.             }
  212.             $string .= "\n";
  213.         else {
  214.             $string .= "msgstr \"$this->msgstr\"\n\n";
  215.         }
  216.         return $string;
  217.     }
  218.  
  219. /* end of class PHPGettext_Catalog_Entry */
  220.  
  221. ?>

Documentation generated on Mon, 05 May 2008 16:22:30 +0400 by phpDocumentor 1.4.0