WordPress / WordPress/WordPress-Coding-Standards

Flag translatable strings with multiple different translator comments

Open
#1,444 5 comments 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

Hi all!

I've been encouraged to submit this possible enhancement to WPCS, so here I am :-)

Most recently I've been working on wp-cli/i18n-command, a WP-CLI command used to create POT files from WordPress projects (core, plugins, themes).

Since I've always liked the I18N sniffs in WPCS, I decided to incorporate something similar to flag strings with missing translator comments and the like.

The relevant part of the code can be found here: https://github.com/wp-cli/i18n-command/blob/963a56727d9215282c373452cb0fda0bea654879/src/MakePotCommand.php#L561-L656.

If you want to test it yourself, you can download the command individually or install WP-CLI 2.0 (currently via wp cli update --nightly) and then run wp i18n make-pot /path/to/source.

One piece that is included but isn't part of WPCS is a check for strings with multiple different translator comments. This can be potentially bad for translators because they

a) see multiple different translator comments in their translation tool (Poedit, translate.wordpress.org)
b) strings can have different translations depending on the / variables

When encountering such a string it's usually a good sign that the translator comments should either be consolidated/unified so they're all the same, or that the strings should be separated completely by adding a different gettext context.

For example, the string More information about %s exists three times in WordPress core. Once, the translator comment is %s: plugin name and version, the second time it's %s: Importer name and in the third instance there's no comment at all.

The WP-CLI command then prints a warning like this:

Warning: The string "More information about %s" has 2 different translator comments. (wp-admin/import.php:175)

Note that the WP-CLI command does not print that warning when two strings have a different gettext context already. In that case, they're treated as two separate strings with a single translator comment each.

If this is something WPCS could handle as well, I'm sure it would benefit many developers by making their strings even better translatable.

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 referenced MakePotCommand.php section in wp-cli/i18n-command and the existing WPCS internationalization sniffs. Determine how the command identifies multiple translator comments while treating different gettext contexts separately. Done means WPCS reports the conflicting-comment case with a focused test covering the example behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
internationalization, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.