PO::match_begin_and_end_newlines()

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

PO::match_begin_and_end_newlines($translation, $original)

源文件

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