-
Notifications
You must be signed in to change notification settings - Fork 4.4k
ESLint: Enforce stricter translator comment placeholder matching #70458
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
base: trunk
Are you sure you want to change the base?
ESLint: Enforce stricter translator comment placeholder matching #70458
Conversation
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @USERSATOSHI! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
What?
Closes #70453
This Pull Request aims to provide stricter translators comments via eslint.
Changes includes addition of placeholders in translator comments if the placeholders are being used in the below code.
Supports
Placeholders
%s
,%d
and%f
( with and without colon )1
,%1
,%1{s|d|f}
and%1${s|d|f}
named
,%named
Missing Placeholders
Extra/Outdated Placeholders
named:
being false positive in some cases )Why?
Current eslint rule only checks if translators comment is present or not which works but can be improved to force stricter checks like adding correct placeholders and removing extra placeholders.
This Pull Request aims this by checking the type of placeholder for unnamed, named and indexed and use that as inference to match with translators comments.
How?
This PR introduces 2 new helpers
extractPlaceholders
: This extracts the placeholder being used in sprintfextractTranslatorKeys
: This extracts the placeholder used in translator commentsand a new Regex:
REGEXP_COMMENT_PLACEHOLDER
: This regex matches the placeholders present in translators comments.Using these 2 functions we can extract the placeholders used in sprintf and the one in comments and match against each other to find missing and extra placeholders.
Testing Instructions
npm run test:unit packages/eslint-plugin/rules/__tests__/i18n-translator-comments.js
Screenshots or screencast
Missing Placeholders in translator comments
Extra placeholder