Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I18n: Report the translatable strings with leading and trailing spaces #2501

Open
1 task done
amieiro opened this issue Oct 24, 2024 · 1 comment · May be fixed by #2504
Open
1 task done

I18n: Report the translatable strings with leading and trailing spaces #2501

amieiro opened this issue Oct 24, 2024 · 1 comment · May be fixed by #2504

Comments

@amieiro
Copy link

amieiro commented Oct 24, 2024

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.
@jrfnl
Copy link
Member

jrfnl commented Oct 24, 2024

Sounds like a reasonable request and not that hard to implement.

This should, however, NOT be auto-fixable as there may be consequences to removing the space(s) in how the text is displayed, i.e. a space may need to be added in a hard-coded, non-translatable string elsewhere to mitigate the space removal and WPCS will not be able to determine that or to make the extra fix which is needed, which would leave the application is a broken state if WPCS would auto-fix.

@amieiro amieiro linked a pull request Nov 4, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants