WordPress / WordPress/WordPress-Coding-Standards
I18n: Report the translatable strings with leading and trailing spaces
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.8k
- Forks
- 521
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 1
Description
Is your feature request related to a problem?
At translate.w.org, sometimes we get translations that start or end with one or more empty spaces, and we want to avoid this. We have added some flags to GlotPress to show them, but ideally they should not appear in the English strings (the strings to be translated), as it is indicated in the “Best practices” of How to Internationalize Your Plugin: Do not leave leading or trailing whitespace in a translatable phrase.
Some examples of incorrect strings in the translation system: 1, 2, 3, 4.
Describe the solution you'd like
When a user will execute phpcs, I would like to see these errors, with an option to resolve them with phpcbf.
FILE: /Users/my-user/wordpress/wp-content/plugins/my-plugin/index.php
---------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
---------------------------------------------------------------------
1 | ERROR | [x] The translatable string can't start with one or more empty spaces
2 | ERROR | [x] The translatable string can't end with one or more empty spaces
---------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------
Additional context (optional)
- I intend to create a pull request to implement this feature.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names phpcs and phpcbf but no repository file or test entry point; begin by locating the internationalization sniff that should report these strings. Validate the requested leading- and trailing-space examples, and confirm that phpcs reports both violations while phpcbf resolves them.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- internationalization, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100