PO::poify()

最后更新于:2021-11-25 21:25:50

PO::poify( string$string)

Formats a string in PO-style

参数

$string

(string) (Required) the string to format

响应

(string) the poified string

源文件

文件: gc-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;
		}