web/wp-includes/pomo/po.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * Class for working with PO files
     3  * Class for working with PO files
     4  *
     4  *
     5  * @version $Id: po.php 283 2009-09-23 16:21:51Z nbachiyski $
     5  * @version $Id: po.php 589 2010-12-18 01:40:57Z nbachiyski $
     6  * @package pomo
     6  * @package pomo
     7  * @subpackage po
     7  * @subpackage po
     8  */
     8  */
     9 
     9 
    10 require_once dirname(__FILE__) . '/translations.php';
    10 require_once dirname(__FILE__) . '/translations.php';
    17  * Routines for working with PO files
    17  * Routines for working with PO files
    18  */
    18  */
    19 if ( !class_exists( 'PO' ) ):
    19 if ( !class_exists( 'PO' ) ):
    20 class PO extends Gettext_Translations {
    20 class PO extends Gettext_Translations {
    21 	
    21 	
       
    22 	var $comments_before_headers = '';
    22 
    23 
    23 	/**
    24 	/**
    24 	 * Exports headers to a PO entry
    25 	 * Exports headers to a PO entry
    25 	 *
    26 	 *
    26 	 * @return string msgid/msgstr PO entry for this PO file headers, doesn't contain newline at the end
    27 	 * @return string msgid/msgstr PO entry for this PO file headers, doesn't contain newline at the end
    29 		$header_string = '';
    30 		$header_string = '';
    30 		foreach($this->headers as $header => $value) {
    31 		foreach($this->headers as $header => $value) {
    31 			$header_string.= "$header: $value\n";
    32 			$header_string.= "$header: $value\n";
    32 		}
    33 		}
    33 		$poified = PO::poify($header_string);
    34 		$poified = PO::poify($header_string);
    34 		return rtrim("msgid \"\"\nmsgstr $poified");
    35 		if ($this->comments_before_headers)
       
    36 			$before_headers = $this->prepend_each_line(rtrim($this->comments_before_headers)."\n", '# ');
       
    37 		else
       
    38 			$before_headers = '';
       
    39 		return rtrim("{$before_headers}msgid \"\"\nmsgstr $poified");
    35 	}
    40 	}
    36 
    41 
    37 	/**
    42 	/**
    38 	 * Exports all entries to PO format
    43 	 * Exports all entries to PO format
    39 	 *
    44 	 *
    72 		if (false === $fh) return false;
    77 		if (false === $fh) return false;
    73 		$export = $this->export($include_headers);
    78 		$export = $this->export($include_headers);
    74 		$res = fwrite($fh, $export);
    79 		$res = fwrite($fh, $export);
    75 		if (false === $res) return false;
    80 		if (false === $res) return false;
    76 		return fclose($fh);
    81 		return fclose($fh);
       
    82 	}
       
    83 	
       
    84 	/**
       
    85 	 * Text to include as a comment before the start of the PO contents
       
    86 	 * 
       
    87 	 * Doesn't need to include # in the beginning of lines, these are added automatically
       
    88 	 */
       
    89 	function set_comment_before_headers( $text ) {
       
    90 		$this->comments_before_headers = $text;
    77 	}
    91 	}
    78 
    92 
    79 	/**
    93 	/**
    80 	 * Formats a string in PO-style
    94 	 * Formats a string in PO-style
    81 	 *
    95 	 *