PO
- Source
wp-includes/pomo/po.php:20
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
- export_headers()Exports headers to a PO entry
- export_entries()Exports all entries to PO format
- export()Exports the whole PO file as a string
- export_to_file()Same as {@link export}, but writes the result to a file
- set_comment_before_headers()Text to include as a comment before the start of the PO contents
- poify()Formats a string in PO-style
- unpoify()Gives back the original string from a PO-formatted string
- prepend_each_line()Inserts $with in the beginning of every new line of $input_string and returns the modified string
- comment_block()Prepare a text as a comment -- wraps the lines and prepends # and a special character to each line
- export_entry()Builds a string from the entry for inclusion in PO file
- match_begin_and_end_newlines()
- import_from_file()
- is_final()Helper function for read_entry
- read_entry()
- read_line()
- add_comment_to_entry()
- trim_quotes()
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 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.