PO::match_begin_and_end_newlines() WordPress Method

The match_begin_and_end_newlines() method is a Wordpress function that is used to match the beginning and end of newlines in a string. This function is useful for doing things like matching the beginning and end of a paragraph.

PO::match_begin_and_end_newlines( $translation,  $original ) #


Source

File: wp-includes/pomo/po.php

		public static function match_begin_and_end_newlines( $translation, $original ) {
			if ( '' === $translation ) {
				return $translation;
			}

			$original_begin    = "\n" === substr( $original, 0, 1 );
			$original_end      = "\n" === substr( $original, -1 );
			$translation_begin = "\n" === substr( $translation, 0, 1 );
			$translation_end   = "\n" === substr( $translation, -1 );

			if ( $original_begin ) {
				if ( ! $translation_begin ) {
					$translation = "\n" . $translation;
				}
			} elseif ( $translation_begin ) {
				$translation = ltrim( $translation, "\n" );
			}

			if ( $original_end ) {
				if ( ! $translation_end ) {
					$translation .= "\n";
				}
			} elseif ( $translation_end ) {
				$translation = rtrim( $translation, "\n" );
			}

			return $translation;
		}

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.