WordPress/Sniffs/WP/I18nSniff.php
protected function check_for_translator_comment( $stack_ptr, $args ) {
		foreach ( $args as $arg ) {
			if ( false === \in_array( $arg['arg_name'], array( 'text', 'single', 'plural' ), true ) ) {
				continue;
			}

			if ( empty( $arg['tokens'] ) ) {
				continue;
			}

			foreach ( $arg['tokens'] as $token ) {
				if ( empty( $token['content'] ) ) {
					continue;
				}

				if ( preg_match( self::SPRINTF_PLACEHOLDER_REGEX, $token['content'], $placeholders ) < 1 ) {
					// No placeholders found.
					continue;
				}

				$previous_comment = $this->phpcsFile->findPrevious( Tokens::$commentTokens, ( $stack_ptr - 1 ) );

				if ( false !== $previous_comment ) {
					/*
					 * Check that the comment is either on the line before the gettext call or
					 * if it's not, that there is only whitespace between.
					 */
					$correctly_placed = false;

					if ( ( $this->tokens[ $previous_comment ]['line'] + 1 ) === $this->tokens[ $stack_ptr ]['line'] ) {
						$correctly_placed = true;
					} else {
						$next_non_whitespace = $this->phpcsFile->findNext( \T_WHITESPACE, ( $previous_comment + 1 ), $stack_ptr, true );
						if ( false === $next_non_whitespace || $this->tokens[ $next_non_whitespace ]['line'] === $this->tokens[ $stack_ptr ]['line'] ) {
							// No non-whitespace found or next non-whitespace is on same line as gettext call.
							$correctly_placed = true;
						}
						unset( $next_non_whitespace );
					}

					/*
					 * Check that the comment starts with 'translators:'.
					 */
					if ( true === $correctly_placed ) {

						if ( \T_COMMENT === $this->tokens[ $previous_comment ]['code'] ) {
							$comment_text = trim( $this->tokens[ $previous_comment ]['content'] );

							// If it's multi-line /* */ comment, collect all the parts.
							if ( '*/' === substr( $comment_text, -2 ) && '/*' !== substr( $comment_text, 0, 2 ) ) {
								for ( $i = ( $previous_comment - 1 ); 0 <= $i; $i-- ) {
									if ( \T_COMMENT !== $this->tokens[ $i ]['code'] ) {
										break;
									}

									$comment_text = trim( $this->tokens[ $i ]['content'] ) . $comment_text;
								}
							}

							if ( true === $this->is_translators_comment( $comment_text ) ) {
								// Comment is ok.
								return;
							}
						} elseif ( \T_DOC_COMMENT_CLOSE_TAG === $this->tokens[ $previous_comment ]['code'] ) {
							// If it's docblock comment (wrong style) make sure that it's a translators comment.
							$db_start      = $this->phpcsFile->findPrevious( \T_DOC_COMMENT_OPEN_TAG, ( $previous_comment - 1 ) );
							$db_first_text = $this->phpcsFile->findNext( \T_DOC_COMMENT_STRING, ( $db_start + 1 ), $previous_comment );

							if ( true === $this->is_translators_comment( $this->tokens[ $db_first_text ]['content'] ) ) {
								$this->phpcsFile->addWarning(
									'A "translators:" comment must be a "/* */" style comment. Docblock comments will not be picked up by the tools to generate a ".pot" file.',
									$stack_ptr,
									'TranslatorsCommentWrongStyle'
								);
								return;
							}
						}
					}
				}

				// Found placeholders but no translators comment.
				$this->phpcsFile->addWarning(
					'A gettext call containing placeholders was found, but was not accompanied by a "translators:" comment on the line above to clarify the meaning of the placeholders.',
					$stack_ptr,
					'MissingTranslatorsComment'
				);
				return;
			}
		}
	}
protected function check_for_translator_comment( $stack_ptr, $args ) {
		foreach ( $args as $arg ) {
			if ( false === \in_array( $arg['arg_name'], array( 'text', 'single', 'plural' ), true ) ) {
				continue;
			}

			if ( empty( $arg['tokens'] ) ) {
				continue;
			}

			foreach ( $arg['tokens'] as $token ) {
				if ( empty( $token['content'] ) ) {
					continue;
				}

				if ( preg_match( self::SPRINTF_PLACEHOLDER_REGEX, $token['content'], $placeholders ) < 1 ) {
					// No placeholders found.
					continue;
				}

				$previous_comment = $this->phpcsFile->findPrevious( Tokens::$commentTokens, ( $stack_ptr - 1 ) );

				if ( false !== $previous_comment ) {
					/*
					 * Check that the comment is either on the line before the gettext call or
					 * if it's not, that there is only whitespace between.
					 */
					$correctly_placed = false;

					if ( ( $this->tokens[ $previous_comment ]['line'] + 1 ) === $this->tokens[ $stack_ptr ]['line'] ) {
						$correctly_placed = true;
					} else {
						$next_non_whitespace = $this->phpcsFile->findNext( \T_WHITESPACE, ( $previous_comment + 1 ), $stack_ptr, true );
						if ( false === $next_non_whitespace || $this->tokens[ $next_non_whitespace ]['line'] === $this->tokens[ $stack_ptr ]['line'] ) {
							// No non-whitespace found or next non-whitespace is on same line as gettext call.
							$correctly_placed = true;
						}
						unset( $next_non_whitespace );
					}

					/*
					 * Check that the comment starts with 'translators:'.
					 */
					if ( true === $correctly_placed ) {

						if ( \T_COMMENT === $this->tokens[ $previous_comment ]['code'] ) {
							$comment_text = trim( $this->tokens[ $previous_comment ]['content'] );

							// If it's multi-line /* */ comment, collect all the parts.
							if ( '*/' === substr( $comment_text, -2 ) && '/*' !== substr( $comment_text, 0, 2 ) ) {
								for ( $i = ( $previous_comment - 1 ); 0 <= $i; $i-- ) {
									if ( \T_COMMENT !== $this->tokens[ $i ]['code'] ) {
										break;
									}

									$comment_text = trim( $this->tokens[ $i ]['content'] ) . $comment_text;
								}
							}

							if ( true === $this->is_translators_comment( $comment_text ) ) {
								// Comment is ok.
								return;
							}
						} elseif ( \T_DOC_COMMENT_CLOSE_TAG === $this->tokens[ $previous_comment ]['code'] ) {
							// If it's docblock comment (wrong style) make sure that it's a translators comment.
							$db_start      = $this->phpcsFile->findPrevious( \T_DOC_COMMENT_OPEN_TAG, ( $previous_comment - 1 ) );
							$db_first_text = $this->phpcsFile->findNext( \T_DOC_COMMENT_STRING, ( $db_start + 1 ), $previous_comment );

							if ( true === $this->is_translators_comment( $this->tokens[ $db_first_text ]['content'] ) ) {
								$this->phpcsFile->addWarning(
									'A "translators:" comment must be a "/* */" style comment. Docblock comments will not be picked up by the tools to generate a ".pot" file.',
									$stack_ptr,
									'TranslatorsCommentWrongStyle'
								);
								return;
							}
						}
					}
				}

				// Found placeholders but no translators comment.
				$this->phpcsFile->addWarning(
					'A gettext call containing placeholders was found, but was not accompanied by a "translators:" comment on the line above to clarify the meaning of the placeholders.',
					$stack_ptr,
					'MissingTranslatorsComment'
				);
				return;
			}
		}
	}
Check for the presence of a translators comment if one of the text strings contains a placeholder.

@param int   $stack_ptr  The position of the gettext call token in the stack.
@param array $args       The function arguments.
@return void