wp/wp-includes/pomo/po.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
--- a/wp/wp-includes/pomo/po.php	Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/pomo/po.php	Tue Dec 15 13:49:49 2020 +0100
@@ -7,7 +7,7 @@
  * @subpackage po
  */
 
-require_once dirname( __FILE__ ) . '/translations.php';
+require_once __DIR__ . '/translations.php';
 
 if ( ! defined( 'PO_MAX_LINE_LEN' ) ) {
 	define( 'PO_MAX_LINE_LEN', 79 );
@@ -48,7 +48,7 @@
 		 * @return string sequence of mgsgid/msgstr PO strings, doesn't containt newline at the end
 		 */
 		function export_entries() {
-			//TODO sorting
+			// TODO: Sorting.
 			return implode( "\n\n", array_map( array( 'PO', 'export_entry' ), $this->entries ) );
 		}
 
@@ -71,8 +71,8 @@
 		/**
 		 * 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 tje headers in the export
+		 * @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
 		 */
 		function export_to_file( $filename, $include_headers = true ) {
@@ -92,6 +92,8 @@
 		 * 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.
 		 */
 		function set_comment_before_headers( $text ) {
 			$this->comments_before_headers = $text;
@@ -117,12 +119,12 @@
 			$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
+			// Add empty string on first line for readbility.
 			if ( false !== strpos( $string, $newline ) &&
-				( substr_count( $string, $newline ) > 1 || ! ( $newline === substr( $string, -strlen( $newline ) ) ) ) ) {
+				( substr_count( $string, $newline ) > 1 || substr( $string, -strlen( $newline ) ) !== $newline ) ) {
 				$po = "$quote$quote$newline$po";
 			}
-			// remove empty strings
+			// Remove empty strings.
 			$po = str_replace( "$newline$quote$quote", '', $po );
 			return $po;
 		}
@@ -149,7 +151,7 @@
 				$chars = $chars[0];
 				foreach ( $chars as $char ) {
 					if ( ! $previous_is_backslash ) {
-						if ( '\\' == $char ) {
+						if ( '\\' === $char ) {
 							$previous_is_backslash = true;
 						} else {
 							$unpoified .= $char;
@@ -161,7 +163,7 @@
 				}
 			}
 
-			// Standardise the line endings on imported content, technically PO files shouldn't contain \r
+			// Standardise the line endings on imported content, technically PO files shouldn't contain \r.
 			$unpoified = str_replace( array( "\r\n", "\r" ), "\n", $unpoified );
 
 			return $unpoified;
@@ -178,9 +180,11 @@
 			$lines  = explode( "\n", $string );
 			$append = '';
 			if ( "\n" === substr( $string, -1 ) && '' === end( $lines ) ) {
-				// Last line might be empty because $string was terminated
-				// with a newline, remove it from the $lines array,
-				// we'll restore state by re-terminating the string at the end
+				/*
+				 * Last line might be empty because $string was terminated
+				 * with a newline, remove it from the $lines array,
+				 * we'll restore state by re-terminating the string at the end.
+				 */
 				array_pop( $lines );
 				$append = "\n";
 			}
@@ -209,7 +213,7 @@
 		 * Builds a string from the entry for inclusion in PO file
 		 *
 		 * @param Translation_Entry $entry the entry to convert to po string (passed by reference).
-		 * @return false|string PO-style formatted string for the entry or
+		 * @return string|false PO-style formatted string for the entry or
 		 *  false if the entry is empty
 		 */
 		public static function export_entry( &$entry ) {
@@ -292,7 +296,7 @@
 				if ( ! $res ) {
 					break;
 				}
-				if ( $res['entry']->singular == '' ) {
+				if ( '' === $res['entry']->singular ) {
 					$this->set_headers( $this->make_headers( $res['entry']->translations[0] ) );
 				} else {
 					$this->add_entry( $res['entry'] );
@@ -315,7 +319,7 @@
 		 * @return bool
 		 */
 		protected static function is_final( $context ) {
-			return ( $context === 'msgstr' ) || ( $context === 'msgstr_plural' );
+			return ( 'msgstr' === $context ) || ( 'msgstr_plural' === $context );
 		}
 
 		/**
@@ -325,8 +329,8 @@
 		 */
 		function read_entry( $f, $lineno = 0 ) {
 			$entry = new Translation_Entry();
-			// where were we in the last step
-			// can be: comment, msgctxt, msgid, msgid_plural, msgstr, msgstr_plural
+			// Where were we in the last step.
+			// Can be: comment, msgctxt, msgid, msgid_plural, msgstr, msgstr_plural.
 			$context      = '';
 			$msgstr_index = 0;
 			while ( true ) {
@@ -336,7 +340,7 @@
 					if ( feof( $f ) ) {
 						if ( self::is_final( $context ) ) {
 							break;
-						} elseif ( ! $context ) { // we haven't read a line and eof came
+						} elseif ( ! $context ) { // We haven't read a line and EOF came.
 							return null;
 						} else {
 							return false;
@@ -345,22 +349,22 @@
 						return false;
 					}
 				}
-				if ( $line == "\n" ) {
+				if ( "\n" === $line ) {
 					continue;
 				}
 				$line = trim( $line );
 				if ( preg_match( '/^#/', $line, $m ) ) {
-					// the comment is the start of a new entry
+					// The comment is the start of a new entry.
 					if ( self::is_final( $context ) ) {
 						PO::read_line( $f, 'put-back' );
 						$lineno--;
 						break;
 					}
-					// comments have to be at the beginning
-					if ( $context && $context != 'comment' ) {
+					// Comments have to be at the beginning.
+					if ( $context && 'comment' !== $context ) {
 						return false;
 					}
-					// add comment
+					// Add comment.
 					$this->add_comment_to_entry( $entry, $line );
 				} elseif ( preg_match( '/^msgctxt\s+(".*")/', $line, $m ) ) {
 					if ( self::is_final( $context ) ) {
@@ -368,7 +372,7 @@
 						$lineno--;
 						break;
 					}
-					if ( $context && $context != 'comment' ) {
+					if ( $context && 'comment' !== $context ) {
 						return false;
 					}
 					$context         = 'msgctxt';
@@ -379,26 +383,26 @@
 						$lineno--;
 						break;
 					}
-					if ( $context && $context != 'msgctxt' && $context != 'comment' ) {
+					if ( $context && 'msgctxt' !== $context && 'comment' !== $context ) {
 						return false;
 					}
 					$context          = 'msgid';
 					$entry->singular .= PO::unpoify( $m[1] );
 				} elseif ( preg_match( '/^msgid_plural\s+(".*")/', $line, $m ) ) {
-					if ( $context != 'msgid' ) {
+					if ( 'msgid' !== $context ) {
 						return false;
 					}
 					$context          = 'msgid_plural';
 					$entry->is_plural = true;
 					$entry->plural   .= PO::unpoify( $m[1] );
 				} elseif ( preg_match( '/^msgstr\s+(".*")/', $line, $m ) ) {
-					if ( $context != 'msgid' ) {
+					if ( 'msgid' !== $context ) {
 						return false;
 					}
 					$context             = 'msgstr';
 					$entry->translations = array( PO::unpoify( $m[1] ) );
 				} elseif ( preg_match( '/^msgstr\[(\d+)\]\s+(".*")/', $line, $m ) ) {
-					if ( $context != 'msgid_plural' && $context != 'msgstr_plural' ) {
+					if ( 'msgid_plural' !== $context && 'msgstr_plural' !== $context ) {
 						return false;
 					}
 					$context                      = 'msgstr_plural';
@@ -448,26 +452,23 @@
 		}
 
 		/**
-		 * @staticvar string   $last_line
-		 * @staticvar boolean  $use_last_line
-		 *
-		 * @param     resource $f
-		 * @param     string   $action
+		 * @param resource $f
+		 * @param string   $action
 		 * @return boolean
 		 */
 		function read_line( $f, $action = 'read' ) {
 			static $last_line     = '';
 			static $use_last_line = false;
-			if ( 'clear' == $action ) {
+			if ( 'clear' === $action ) {
 				$last_line = '';
 				return true;
 			}
-			if ( 'put-back' == $action ) {
+			if ( 'put-back' === $action ) {
 				$use_last_line = true;
 				return true;
 			}
 			$line          = $use_last_line ? $last_line : fgets( $f );
-			$line          = ( "\r\n" == substr( $line, -2 ) ) ? rtrim( $line, "\r\n" ) . "\n" : $line;
+			$line          = ( "\r\n" === substr( $line, -2 ) ) ? rtrim( $line, "\r\n" ) . "\n" : $line;
 			$last_line     = $line;
 			$use_last_line = false;
 			return $line;
@@ -480,11 +481,11 @@
 		function add_comment_to_entry( &$entry, $po_comment_line ) {
 			$first_two = substr( $po_comment_line, 0, 2 );
 			$comment   = trim( substr( $po_comment_line, 2 ) );
-			if ( '#:' == $first_two ) {
+			if ( '#:' === $first_two ) {
 				$entry->references = array_merge( $entry->references, preg_split( '/\s+/', $comment ) );
-			} elseif ( '#.' == $first_two ) {
+			} elseif ( '#.' === $first_two ) {
 				$entry->extracted_comments = trim( $entry->extracted_comments . "\n" . $comment );
-			} elseif ( '#,' == $first_two ) {
+			} elseif ( '#,' === $first_two ) {
 				$entry->flags = array_merge( $entry->flags, preg_split( '/,\s*/', $comment ) );
 			} else {
 				$entry->translator_comments = trim( $entry->translator_comments . "\n" . $comment );
@@ -493,13 +494,13 @@
 
 		/**
 		 * @param string $s
-		 * @return sring
+		 * @return string
 		 */
 		public static function trim_quotes( $s ) {
-			if ( substr( $s, 0, 1 ) == '"' ) {
+			if ( '"' === substr( $s, 0, 1 ) ) {
 				$s = substr( $s, 1 );
 			}
-			if ( substr( $s, -1, 1 ) == '"' ) {
+			if ( '"' === substr( $s, -1, 1 ) ) {
 				$s = substr( $s, 0, -1 );
 			}
 			return $s;