WordPress / WordPress/WordPress-Coding-Standards

Increase the strictness of the translator comment sniff

Open
#1,229 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Focus: I18n Type: Enhancement
Dominant language
PHP
Stars
2.8k
Forks
521
Avg merge
5d 20h
Merged PRs (30d)
1

Description

When sniffing for translator comments, the contents of the comment is not taken into consideration. This means that there's no check to ensure the placeholder notation in the comment matches the available placeholders in the localised string.

The reason for this is that such sniffing is potentially error prone. From https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/423#issuecomment-269061587:

I will currently not address checking the number of placeholders against the translators comment as the formats used vary and this would IMHO be extremely prone to bugs. See the below examples to illustrate what I mean:

/* translators: 1. number of monkeys, 2. location. */
/* translators: %1$d: number of monkeys, %2$s: location. */
/* translators: %d - number of monkeys, %s - location. */
/* translators: number of monkeys, location. */
__( 'There are %1$d monkeys in the %2$s', 'my-slug' );

That said, the 41057 project presents an opportunity to standardise on the format used in translator comments, so that their format can be made more strict and therefore be made sniffable for accuracy.

Background: A plugin of mine had a mismatching translator comment (%s vs %d) and was confusing translators.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the translator comment sniff and the linked WordPress core ticket, then compare the placeholder formats shown in this issue. Done means the agreed translator-comment format is validated against the localized string's placeholders without misclassifying supported formats.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.