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

ESLint: Improve lint regex for preventing "toggle" word usage in translation ready functions #68958

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

im3dabasia
Copy link
Contributor

Related Comment: #67741 (comment)

Related issue: #66372

What?

As described in the above comment, after the new rule had been added to prevent the usage of the word "toggle" in the repositiory. The solution merged previoulsy could be optimised better by improving the regex.

Why?

Previously the word toggle was only detected/flaagged incase if it were the first word in the string ie __("toggle is the first word") but if "toggle" was used in the middle or at the end it would not be flagged.

How?

Updated the regex of the eslint rule to further improve the warning. and prevent usage of the word toggle.

The new regex: Literal[value=/toggle\\b/i]

Screencast

Before

Screen.Recording.2025-01-29.at.11.18.42.PM.mov

After

Screen.Recording.2025-01-29.at.11.26.02.PM.mov

@im3dabasia im3dabasia marked this pull request as ready for review January 30, 2025 08:37
Copy link

github-actions bot commented Jan 30, 2025

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: im3dabasia <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: swissspidy <[email protected]>
Co-authored-by: afercia <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano added Internationalization (i18n) Issues or PRs related to internationalization efforts [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. labels Jan 31, 2025
@im3dabasia
Copy link
Contributor Author

Hi @swissspidy,

When you have a moment, could you please review my PR after I shared my observation in this comment

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Toggle" in the beginning of a string was most likely imperative, where we can easily say it was used as a verb.

That won't be the case for mid-sentence use, though. And what's wrong with "toggle" as a noun?

@swissspidy
Copy link
Member

That won't be the case for mid-sentence use, though. And what's wrong with "toggle" as a noun?

We can't know whether it's used as a noun or verb. If there's a legitimate use then the rule can be disabled in that specific location.

@tyxla
Copy link
Member

tyxla commented Feb 6, 2025

I see, and that's my point: if a rule can often be a false alarm, then it may harm more than it helps, and it's debatable whether it makes sense to have in the first place.

However, I don't have strong feelings either way.

@swissspidy
Copy link
Member

The keyword here is often. Usage of the word "toggle" is very rare, and it's rarely used as a noun.

This PR here flags a few new places, all of which are correct because the word is used as a verb:

/* translators: accessibility text (hint for switches) */
__( 'Double tap to toggle setting' )

'Tools provide different sets of interactions for blocks. Toggle between simplified content tools (Write) and advanced visual editing tools (Design).'

'Nested blocks will fill the width of this container. Toggle to constrain.'

/* translators: accessibility text (hint for switches) */
__( 'Double tap to toggle setting' )

No false positives.

If we can fix these instances in this PR then this is good to go IMO.

@im3dabasia
Copy link
Contributor Author

@tyxla and @swissspidy ,

What would you suggest as the best replacement for these strings? I'd appreciate your guidance and advice.

  • Alternative suggestions for the string Double tap to toggle setting

      1. "Double tap to switch setting" 
      2. "Double tap to change setting"
      3. "Double tap to enable or disable"
      4. "Double tap to turn on/off"
      5. "Double tap to adjust setting"
    
  • Alternative suggestions for the string 'Tools provide different sets of interactions for blocks. Toggle between simplified content tools (Write) and advanced visual editing tools (Design).'

        1. "Tools provide different sets of interactions for blocks. Switch between simplified content tools (Write) and advanced visual editing tools (Design)."
        2. "Tools provide different sets of interactions for blocks. Choose between simplified content tools (Write) and advanced visual editing tools (Design)."
        3. "Tools provide different sets of interactions for blocks. Alternate between simplified content tools (Write) and advanced visual editing tools (Design)."
    
  • Alternative suggestions for the string 'Nested blocks will fill the width of this container. Toggle to constrain.'

      1. "Nested blocks will fill the width of this container. Switch to constrain."
      2. "Nested blocks will fill the width of this container. Enable to constrain."
      3. "Nested blocks will fill the width of this container. Adjust to constrain."
    
  • Alternative suggestions for string 'Double tap to toggle setting this one'

      1. "Double tap to switch setting."
      2. "Double tap to change setting."
      3. "Double tap to adjust setting."
    

@swissspidy
Copy link
Member

^ Also @afercia

@afercia
Copy link
Contributor

afercia commented Feb 7, 2025

My personal votes:

Double tap to toggle setting
I can't test it and I'm uncomfortable contributing to the native files. Anyways, I'd vote for change.

Double tap to toggle setting this one
Not sure I can find this string.

Tools provide different sets of interactions for blocks. Toggle between simplified content tools (Write) and advanced visual editing tools (Design)
I'd vote for 2.

Nested blocks will fill the width of this container. Toggle to constrain.
I'd rather remove Toggle to constrain. entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internationalization (i18n) Issues or PRs related to internationalization efforts [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants