Skip to content

ESLint: make translator-comments rule more strict #70453

@swissspidy

Description

@swissspidy

What problem does this address?

Right now, the i18n-translator-comments ESLint rule in eslint-plugin only checks whether a translatable string with placeholders is missing a translator comment or not. See https://github.com/WordPress/gutenberg/blob/de11ef92c9f6478fedb7bd5f56b1612943d5c7a9/packages/eslint-plugin/rules/i18n-translator-comments.js

While working on #70434 I noticed that the quality of some of the comments is sub-optimal, as they don't actually reference the placeholders.

Bad:

// translators: Current page number in total number of pages
__( 'Page %1$s of %2$s' )

/* translators: The number of items. */
__( '%s items reset.' )

Good:

// translators: 1: current page number. 2: total number of pages.
__( 'Page %1$d of %2$d' )

/* translators: %d: The number of items. */
__( '%d items reset.' ),

What is your proposed solution?

It would be nice if the rule was a bit stricter and used some regex to enforce that every placeholder is mentioned in comment.

They usually follow this format (single placeholder vs multiple):

translators: %d: foo.
translators: %s: bar.

translators: 1: foo. 2: bar.
translators: 1: foo, 2: bar.
translators: 1 is foo. 2 is bar.
translators: 1 is foo, 2 is bar.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions