wppaste
WordPress

PO

Source
wp-includes/pomo/po.php:30

Compatibility

WordPress
core
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Properties · 1

$comments_before_headerspublic

Methods · 17

Source code

	class PO extends Gettext_Translations { 		public $comments_before_headers = ''; 		/**		 * Exports headers to a PO entry		 *		 * @return string msgid/msgstr PO entry for this PO file headers, doesn't contain newline at the end		 */		public function export_headers() {			$header_string = '';			foreach ( $this->headers as $header => $value ) {				$header_string .= "$header: $value\n";			}			$poified = PO::poify( $header_string );			if ( $this->comments_before_headers ) {				$before_headers = $this->prepend_each_line( rtrim( $this->comments_before_headers ) . "\n", '# ' );			} else {				$before_headers = '';			}			return rtrim( "{$before_headers}msgid \"\"\nmsgstr $poified" );		} 		/**		 * Exports all entries to PO format		 *		 * @return string sequence of msgid/msgstr PO strings, doesn't contain a newline at the end		 */		public function export_entries() {			// TODO: Sorting.			return implode( "\n\n", array_map( array( 'PO', 'export_entry' ), $this->entries ) );		} 		/**		 * Exports the whole PO file as a string		 *		 * @param bool $include_headers whether to include the headers in the export		 * @return string ready for inclusion in PO file string for headers and all the entries		 */		public function export( $include_headers = true ) {			$res = '';			if ( $include_headers ) {				$res .= $this->export_headers();				$res .= "\n\n";			}			$res .= $this->export_entries();			return $res;		} 		/**		 * Same as {@link export}, but writes the result to a file		 *		 * @param string $filename        Where to write the PO string.		 * @param bool   $include_headers Whether to include the headers in the export.		 * @return bool true on success, false on error		 */		public function export_to_file( $filename, $include_headers = true ) {			$fh = fopen( $filename, 'w' );			if ( false === $fh ) {				return false;			}			$export = $this->export( $include_headers );			$res    = fwrite( $fh, $export );			if ( false === $res ) {				return false;			}			return fclose( $fh );		} 		/**		 * Text to include as a comment before the start of the PO contents		 *		 * Doesn't need to include # in the beginning of lines, these are added automatically		 *		 * @param string $text Text to include as a comment.		 */		public function set_comment_before_headers( $text ) {			$this->comments_before_headers = $text;		}

Changelog

Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/pomo/po.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.