gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Review all the 'Add New' strings

Open afercia opened this issue 3 years ago • 12 comments

Description

In WordPress core, there is a well established pattern where all the 'Add New' strings use title case, for example:

__( 'Add New Post' ) __( 'Add New Page' ) __( 'Add New Template' )

In the editor the situation is mixed. Sometimes it's title case, somtimes it's not. For example, even on the same line of code, this string uses inconsistent casing:

( slug === 'post_tag' ? __( 'Add new tag' ) : __( 'Add new Term' ) );

I'd think all these strings should be consistent with what Core does since ages and always use title case. Worth running a search through the entire code base and update all the inconsistent occurrences, where necessary.

See also on Core Trac: https://core.trac.wordpress.org/ticket/47125 https://core.trac.wordpress.org/ticket/58577#comment:11

I'm not sure there is a good reason why tag should be lowercase while Term is title case. Also, the word new should always be title case.

Step-by-step reproduction instructions

  • Run a case insensitive search in the codebase for all the strings that start with Add new.
  • Observe the casing inconsistencies in your search results.

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

afercia avatar Aug 28 '23 10:08 afercia

Do you believe this inconsistent pattern can be an issue for future developers? Should all the 'Add New' strings use title case?

jamestitus299 avatar Sep 01 '23 10:09 jamestitus299

So the changes are to be made like this : Add new tag to " Add New Tag"

xerpa43 avatar Sep 01 '23 11:09 xerpa43

Reviewed the PR and left suggestions. Its close.

alexstine avatar Sep 03 '23 17:09 alexstine

ok, so the issue is solved, I guess.

xerpa43 avatar Sep 04 '23 13:09 xerpa43

Yeah.

jamestitus299 avatar Sep 04 '23 15:09 jamestitus299

Quickly noting that this change in WordPress core https://core.trac.wordpress.org/changeset/56515 aligned all the existing 'Add New' strings with the editor by adding context in the text itseld. So for example the existing string in core:

_x( 'Add New', 'post' )

had been changed to:

__( 'Add New Post' )

That aligns with thte efitor, where there are no occurrences of just Add New and the text is always more specific instead. See https://core.trac.wordpress.org/ticket/47125

afercia avatar Sep 08 '23 13:09 afercia

How present is this bug in practice.

Looking at the associated pull request it seems that the editor pulls in the labels as defined when registering post types and taxonomies, which is good, so are the default strings ever actually used?

If they are, it seems to be a WordPress-Develop bug in which the labels are not being defined correctly causing the editor to duplicate strings unnecessarily. Is this something that needs fixing in WP-Dev so Gutenberg doesn't need to maintain a set of fallbacks? IE, outside of https://github.com/WordPress/wordpress-develop/pull/6585

peterwilsoncc avatar May 22 '24 23:05 peterwilsoncc

Looking at the associated pull request it seems that the editor pulls in the labels as defined when registering post types and taxonomies, which is good, so are the default strings ever actually used?

@peterwilsoncc this issue description includes an example, where you can see the editor sometimes uses its own strings instead of pulling them in from core. I have no idea why. Usign the core strings would avoid inconsistencies, of course.

afercia avatar May 23 '24 07:05 afercia

@afercia Yeah, I saw that but the editor will only use it's own strings if they are registered in core as null. I could only get to the Gutenberg strings with the following change to WP-Dev.

diff --git a/src/wp-includes/class-wp-taxonomy.php b/src/wp-includes/class-wp-taxonomy.php
index 254ea6a15c..60572db868 100644
--- a/src/wp-includes/class-wp-taxonomy.php
+++ b/src/wp-includes/class-wp-taxonomy.php
@@ -624,7 +624,7 @@ final class WP_Taxonomy {
 			'edit_item'                  => array( __( 'Edit Tag' ), __( 'Edit Category' ) ),
 			'view_item'                  => array( __( 'View Tag' ), __( 'View Category' ) ),
 			'update_item'                => array( __( 'Update Tag' ), __( 'Update Category' ) ),
-			'add_new_item'               => array( __( 'Add New Tag' ), __( 'Add New Category' ) ),
+			'add_new_item'               => array( null, null ),
 			'new_item_name'              => array( __( 'New Tag Name' ), __( 'New Category Name' ) ),
 			'separate_items_with_commas' => array( __( 'Separate tags with commas' ), null ),
 			'add_or_remove_items'        => array( __( 'Add or remove tags' ), null ),

Such a case seems like something that should be handled in WP-Dev so that the editor can use const newTermLabel = taxonomy?.labels?.add_new_item ?? '';. Resolving it Wp-Dev would help avoid the issue recurring in Gutenberg.

peterwilsoncc avatar May 23 '24 23:05 peterwilsoncc

Is this issue still open?

lalitkumawat1m avatar Aug 06 '25 03:08 lalitkumawat1m

@lalitkumawat1m, yes, the issue is still open, and the patch from #54132 can be refreshed and merged.

Mamaduka avatar Aug 06 '25 05:08 Mamaduka

Please note that new labeling rules have been introduced in core since this issue was submitted:

https://core.trac.wordpress.org/ticket/61219

In other words, I believe all strings should be standardized with Add {Entity}, not Add new {entity} or Add New {Entity} in Gutenberg as well.

t-hamano avatar Aug 06 '25 07:08 t-hamano