From 5e779974ddda4e66d22a508bc3c79a75c4769497 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 21 Aug 2024 15:43:06 +0200 Subject: [PATCH] ESLint: Enable and enforce remaining i18n rules for the plugin (e.g. no trailing spaces) (#60196) Co-authored-by: Mahesh Bohara --- .eslintrc.js | 2 ++ lib/experiments-page.php | 6 ++--- .../convert-to-group-buttons/index.js | 2 +- .../global-styles/background-panel.js | 2 +- .../get-global-styles-changes.js | 5 +++- packages/block-library/src/group/edit.js | 2 +- .../src/post-navigation-link/edit.js | 7 ++++-- .../src/query/edit/query-content.js | 2 +- .../src/components/welcome-guide/default.js | 22 ++++++++++------- .../font-library-modal/installed-fonts.js | 10 ++++---- .../src/components/welcome-guide/index.js | 22 ++++++++++------- .../src/components/page-attributes/parent.js | 22 ++++++++++------- .../editor/src/components/post-url/index.js | 24 ++++++++++++------- 13 files changed, 78 insertions(+), 50 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 25173a9f0e8a82..13362e76c4e473 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -177,6 +177,8 @@ module.exports = { '@wordpress/dependency-group': 'error', '@wordpress/wp-global-usage': 'error', '@wordpress/react-no-unsafe-timeout': 'error', + '@wordpress/i18n-hyphenated-range': 'error', + '@wordpress/i18n-no-flanking-whitespace': 'error', '@wordpress/i18n-text-domain': [ 'error', { diff --git a/lib/experiments-page.php b/lib/experiments-page.php index b27f6fc2726a2a..fa95923061daff 100644 --- a/lib/experiments-page.php +++ b/lib/experiments-page.php @@ -45,7 +45,7 @@ function gutenberg_initialize_experiments_settings() { add_settings_field( 'gutenberg-sync-collaboration', - __( 'Live Collaboration and offline persistence ', 'gutenberg' ), + __( 'Live Collaboration and offline persistence', 'gutenberg' ), 'gutenberg_display_experiment_field', 'gutenberg-experiments', 'gutenberg_experiments_section', @@ -93,7 +93,7 @@ function gutenberg_initialize_experiments_settings() { add_settings_field( 'gutenberg-form-blocks', - __( 'Form and input blocks ', 'gutenberg' ), + __( 'Form and input blocks', 'gutenberg' ), 'gutenberg_display_experiment_field', 'gutenberg-experiments', 'gutenberg_experiments_section', @@ -105,7 +105,7 @@ function gutenberg_initialize_experiments_settings() { add_settings_field( 'gutenberg-grid-interactivity', - __( 'Grid interactivity ', 'gutenberg' ), + __( 'Grid interactivity', 'gutenberg' ), 'gutenberg_display_experiment_field', 'gutenberg-experiments', 'gutenberg_experiments_section', diff --git a/packages/block-editor/src/components/convert-to-group-buttons/index.js b/packages/block-editor/src/components/convert-to-group-buttons/index.js index 2a015d569e85b4..d2e5fda1e96b7c 100644 --- a/packages/block-editor/src/components/convert-to-group-buttons/index.js +++ b/packages/block-editor/src/components/convert-to-group-buttons/index.js @@ -82,7 +82,7 @@ function ConvertToGroupButton( { > { _x( 'Ungroup', - 'Ungrouping blocks from within a grouping block back into individual blocks within the Editor ' + 'Ungrouping blocks from within a grouping block back into individual blocks within the Editor' ) } ) } diff --git a/packages/block-editor/src/components/global-styles/background-panel.js b/packages/block-editor/src/components/global-styles/background-panel.js index 6391f72a084875..e230e6e600508c 100644 --- a/packages/block-editor/src/components/global-styles/background-panel.js +++ b/packages/block-editor/src/components/global-styles/background-panel.js @@ -451,7 +451,7 @@ function BackgroundImageControls( { onResetImage(); } } > - { __( 'Reset ' ) } + { __( 'Reset' ) } ) } diff --git a/packages/block-editor/src/components/global-styles/get-global-styles-changes.js b/packages/block-editor/src/components/global-styles/get-global-styles-changes.js index c525cf45c6d52e..51e9b16d8048f4 100644 --- a/packages/block-editor/src/components/global-styles/get-global-styles-changes.js +++ b/packages/block-editor/src/components/global-styles/get-global-styles-changes.js @@ -202,7 +202,10 @@ export default function getGlobalStylesChanges( next, previous, options = {} ) { }, {} ) ).map( ( [ key, changeValues ] ) => { const changeValuesLength = changeValues.length; - const joinedChangesValue = changeValues.join( __( ', ' ) ); + const joinedChangesValue = changeValues.join( + /* translators: Used between list items, there is a space after the comma. */ + __( ', ' ) // eslint-disable-line @wordpress/i18n-no-flanking-whitespace + ); switch ( key ) { case 'blocks': { return sprintf( diff --git a/packages/block-library/src/group/edit.js b/packages/block-library/src/group/edit.js index a763bc95e60d7c..352a6fbc77819e 100644 --- a/packages/block-library/src/group/edit.js +++ b/packages/block-library/src/group/edit.js @@ -34,7 +34,7 @@ function GroupEditControls( { tagName, onSelectTagName } ) { 'The
element should represent introductory content, typically a group of introductory or navigational aids.' ), main: __( - 'The
element should be used for the primary content of your document only. ' + 'The
element should be used for the primary content of your document only.' ), section: __( "The
element should represent a standalone portion of the document that can't be better represented by another element." diff --git a/packages/block-library/src/post-navigation-link/edit.js b/packages/block-library/src/post-navigation-link/edit.js index a3a3bf19749774..e27d094feb79ab 100644 --- a/packages/block-library/src/post-navigation-link/edit.js +++ b/packages/block-library/src/post-navigation-link/edit.js @@ -49,8 +49,11 @@ export default function PostNavigationLinkEdit( { const displayArrow = arrowMap[ arrow ]; if ( showTitle ) { - /* translators: Label before for next and previous post. There is a space after the colon. */ - placeholder = isNext ? __( 'Next: ' ) : __( 'Previous: ' ); + placeholder = isNext + ? /* translators: Label before for next and previous post. There is a space after the colon. */ + __( 'Next: ' ) // eslint-disable-line @wordpress/i18n-no-flanking-whitespace + : /* translators: Label before for next and previous post. There is a space after the colon. */ + __( 'Previous: ' ); // eslint-disable-line @wordpress/i18n-no-flanking-whitespace } const ariaLabel = isNext ? __( 'Next post' ) : __( 'Previous post' ); diff --git a/packages/block-library/src/query/edit/query-content.js b/packages/block-library/src/query/edit/query-content.js index be10f88cb911ec..949ffc653420fe 100644 --- a/packages/block-library/src/query/edit/query-content.js +++ b/packages/block-library/src/query/edit/query-content.js @@ -109,7 +109,7 @@ export default function QueryContent( { } ); const htmlElementMessages = { main: __( - 'The
element should be used for the primary content of your document only. ' + 'The
element should be used for the primary content of your document only.' ), section: __( "The
element should represent a standalone portion of the document that can't be better represented by another element." diff --git a/packages/edit-post/src/components/welcome-guide/default.js b/packages/edit-post/src/components/welcome-guide/default.js index c4723c65a33df2..cdaf2c7608b43e 100644 --- a/packages/edit-post/src/components/welcome-guide/default.js +++ b/packages/edit-post/src/components/welcome-guide/default.js @@ -105,16 +105,20 @@ export default function WelcomeGuideDefault() { { __( 'Learn how to use the block editor' ) }

- { __( - 'New to the block editor? Want to learn more about using it? ' + { createInterpolateElement( + __( + "New to the block editor? Want to learn more about using it? Here's a detailed guide." + ), + { + a: ( + + ), + } ) } - - { __( "Here's a detailed guide." ) } -

), diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/installed-fonts.js b/packages/edit-site/src/components/global-styles/font-library-modal/installed-fonts.js index 7ca2a9218c3bb0..9896a9a525d446 100644 --- a/packages/edit-site/src/components/global-styles/font-library-modal/installed-fonts.js +++ b/packages/edit-site/src/components/global-styles/font-library-modal/installed-fonts.js @@ -130,9 +130,11 @@ function InstalledFonts() { } catch ( error ) { setNotice( { type: 'error', - message: - __( 'There was an error updating the font family. ' ) + - error.message, + message: sprintf( + /* translators: %s: error message */ + __( 'There was an error updating the font family. %s' ), + error.message + ), } ); } }; @@ -464,7 +466,7 @@ function ConfirmDeleteDialog( { setNotice( { type: 'error', message: - __( 'There was an error uninstalling the font family. ' ) + + __( 'There was an error uninstalling the font family.' ) + error.message, } ); } diff --git a/packages/edit-widgets/src/components/welcome-guide/index.js b/packages/edit-widgets/src/components/welcome-guide/index.js index 51244956286d8d..bd06234e399b58 100644 --- a/packages/edit-widgets/src/components/welcome-guide/index.js +++ b/packages/edit-widgets/src/components/welcome-guide/index.js @@ -172,16 +172,20 @@ export default function WelcomeGuide() { { __( 'Learn how to use the block editor' ) }

- { __( - 'New to the block editor? Want to learn more about using it? ' + { createInterpolateElement( + __( + "New to the block editor? Want to learn more about using it? Here's a detailed guide." + ), + { + a: ( + + ), + } ) } - - { __( "Here's a detailed guide." ) } -

), diff --git a/packages/editor/src/components/page-attributes/parent.js b/packages/editor/src/components/page-attributes/parent.js index d53d82914f7c1e..1018834d1b9fca 100644 --- a/packages/editor/src/components/page-attributes/parent.js +++ b/packages/editor/src/components/page-attributes/parent.js @@ -274,16 +274,20 @@ export function ParentRow() { } ) }

- { __( - 'They also show up as sub-items in the default navigation menu. ' + { createInterpolateElement( + __( + 'They also show up as sub-items in the default navigation menu. Learn more.' + ), + { + a: ( + + ), + } ) } - - { __( 'Learn more' ) } -

diff --git a/packages/editor/src/components/post-url/index.js b/packages/editor/src/components/post-url/index.js index c2b2ac8826b205..e767ae04f5ec0e 100644 --- a/packages/editor/src/components/post-url/index.js +++ b/packages/editor/src/components/post-url/index.js @@ -3,7 +3,7 @@ */ import { useSelect, useDispatch } from '@wordpress/data'; import { safeDecodeURIComponent, cleanForSlug } from '@wordpress/url'; -import { useState } from '@wordpress/element'; +import { useState, createInterpolateElement } from '@wordpress/element'; import { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; import { @@ -83,14 +83,20 @@ export default function PostURL( { onClose } ) { { isEditable && (
- { __( 'Customize the last part of the URL. ' ) } - - { __( 'Learn more.' ) } - + { createInterpolateElement( + __( + 'Customize the last part of the URL. Learn more.' + ), + { + a: ( + + ), + } + ) }
) }