PO::poify() WordPress Method

The PO::poify() Wordpress method is used to convert a given string to a PO file format. This is useful when creating or editing PO files for use with gettext.

PO::poify( string $string ) #

Formats a string in PO-style


Parameters

$string

(string)(Required)the string to format


Top ↑

Return

(string) the poified string


Top ↑

Source

File: wp-includes/pomo/po.php

		public static function poify( $string ) {
			$quote   = '"';
			$slash   = '\\';
			$newline = "\n";

			$replaces = array(
				"$slash" => "$slash$slash",
				"$quote" => "$slash$quote",
				"\t"     => '\t',
			);

			$string = str_replace( array_keys( $replaces ), array_values( $replaces ), $string );

			$po = $quote . implode( "${slash}n$quote$newline$quote", explode( $newline, $string ) ) . $quote;
			// Add empty string on first line for readbility.
			if ( false !== strpos( $string, $newline ) &&
				( substr_count( $string, $newline ) > 1 || substr( $string, -strlen( $newline ) ) !== $newline ) ) {
				$po = "$quote$quote$newline$po";
			}
			// Remove empty strings.
			$po = str_replace( "$newline$quote$quote", '', $po );
			return $po;
		}

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.