Skip to content

Commit ff8698d

Browse files
oandregalclaude
andcommitted
Entity Fields: Keep code out of translatable strings.
Pass hook names, file names, keys, and method names as placeholders, wrapped in `<code>`, instead of keeping them inside the strings to translate, as core does elsewhere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c478159 commit ff8698d

2 files changed

Lines changed: 58 additions & 20 deletions

File tree

‎src/wp-includes/class-wp-entity-fields-registry.php‎

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,12 @@ public function register( $origin, $kind, $name, $fields, $script_module = null
165165
_doing_it_wrong(
166166
__METHOD__,
167167
sprintf(
168-
/* translators: 1: Entity kind, e.g. postType. 2: Entity name, e.g. page. 3: Comma-separated list of field ids. */
169-
__( 'A field can only be registered once. These fields of %1$s "%2$s" are skipped because they are already registered: %3$s. Use update() to change a registered field, or unregister it first to replace it.' ),
168+
/* translators: 1: Entity kind, e.g. postType. 2: Entity name, e.g. page. 3: Comma-separated list of field ids. 4: update() */
169+
__( 'A field can only be registered once. These fields of %1$s "%2$s" are skipped because they are already registered: %3$s. Use %4$s to change a registered field, or unregister it first to replace it.' ),
170170
$kind,
171171
$name,
172-
implode( ', ', $registered_ids )
172+
implode( ', ', $registered_ids ),
173+
'<code>update()</code>'
173174
),
174175
'7.2.0'
175176
);
@@ -265,11 +266,12 @@ public function update( $origin, $kind, $name, $fields, $script_module = null )
265266
_doing_it_wrong(
266267
__METHOD__,
267268
sprintf(
268-
/* translators: 1: Entity kind, e.g. postType. 2: Entity name, e.g. page. 3: Comma-separated list of field ids. */
269-
__( 'Only registered fields can be updated. These fields of %1$s "%2$s" are skipped because they are not registered: %3$s. Use register() to add a field.' ),
269+
/* translators: 1: Entity kind, e.g. postType. 2: Entity name, e.g. page. 3: Comma-separated list of field ids. 4: register() */
270+
__( 'Only registered fields can be updated. These fields of %1$s "%2$s" are skipped because they are not registered: %3$s. Use %4$s to add a field.' ),
270271
$kind,
271272
$name,
272-
implode( ', ', $unregistered_ids )
273+
implode( ', ', $unregistered_ids ),
274+
'<code>register()</code>'
273275
),
274276
'7.2.0'
275277
);
@@ -528,7 +530,12 @@ protected function initialize() {
528530
if ( ! did_action( 'init' ) || doing_action( 'init' ) ) {
529531
_doing_it_wrong(
530532
__METHOD__,
531-
__( 'The registered fields cannot be read until the `init` action has completed: the post types and supports they derive from are registered on `init`. Read them once `init` has completed, or hook `wp_entity_fields_api_init`.' ),
533+
sprintf(
534+
/* translators: 1: init, 2: wp_entity_fields_api_init */
535+
__( 'The registered fields cannot be read until the %1$s action has completed: the post types and supports they derive from are registered on %1$s. Read them once %1$s has completed, or hook %2$s.' ),
536+
'<code>init</code>',
537+
'<code>wp_entity_fields_api_init</code>'
538+
),
532539
'7.2.0'
533540
);
534541
return;
@@ -577,7 +584,11 @@ protected function doing_entity_fields_api_init( $method ) {
577584

578585
_doing_it_wrong(
579586
$method,
580-
__( 'Fields can only be registered, updated, and unregistered on the `wp_entity_fields_api_init` action.' ),
587+
sprintf(
588+
/* translators: %s: wp_entity_fields_api_init */
589+
__( 'Fields can only be registered, updated, and unregistered on the %s action.' ),
590+
'<code>wp_entity_fields_api_init</code>'
591+
),
581592
'7.2.0'
582593
);
583594
return false;
@@ -731,11 +742,12 @@ protected function skip_invalid_definitions( $method, $kind, $name, $fields ) {
731742
_doing_it_wrong(
732743
$method,
733744
sprintf(
734-
/* translators: 1: Entity kind, e.g. postType. 2: Entity name, e.g. page. 3: Comma-separated list of positions, e.g. #2, #4. */
735-
__( 'Every field definition must be an array with a non-empty string `id`. These definitions of %1$s "%2$s" are skipped: %3$s. The rest of the fields of the call are stored.' ),
745+
/* translators: 1: Entity kind, e.g. postType. 2: Entity name, e.g. page. 3: Comma-separated list of positions, e.g. #2, #4. 4: id */
746+
__( 'Every field definition must be an array with a non-empty string %4$s. These definitions of %1$s "%2$s" are skipped: %3$s. The rest of the fields of the call are stored.' ),
736747
$kind,
737748
$name,
738-
implode( ', ', $invalid )
749+
implode( ', ', $invalid ),
750+
'<code>id</code>'
739751
),
740752
'7.2.0'
741753
);
@@ -809,15 +821,35 @@ protected function get_collection( $method, $directory ) {
809821
$error = null;
810822

811823
if ( ! is_array( $config ) ) {
812-
$error = __( 'The `index.php` of a field collection must return an array.' );
824+
$error = sprintf(
825+
/* translators: %s: index.php */
826+
__( 'The %s of a field collection must return an array.' ),
827+
'<code>index.php</code>'
828+
);
813829
} elseif ( ! isset( $config['origin'] ) || ! is_string( $config['origin'] ) || '' === $config['origin'] ) {
814-
$error = __( 'The `origin` of a field collection must be a non-empty string.' );
830+
$error = sprintf(
831+
/* translators: %s: origin */
832+
__( 'The %s of a field collection must be a non-empty string.' ),
833+
'<code>origin</code>'
834+
);
815835
} elseif ( ! isset( $config['kind'] ) || ! is_string( $config['kind'] ) || '' === $config['kind'] ) {
816-
$error = __( 'The `kind` of a field collection must be a non-empty string.' );
836+
$error = sprintf(
837+
/* translators: %s: kind */
838+
__( 'The %s of a field collection must be a non-empty string.' ),
839+
'<code>kind</code>'
840+
);
817841
} elseif ( ! isset( $config['name'] ) || ! is_string( $config['name'] ) || '' === $config['name'] ) {
818-
$error = __( 'The `name` of a field collection must be a non-empty string.' );
842+
$error = sprintf(
843+
/* translators: %s: name */
844+
__( 'The %s of a field collection must be a non-empty string.' ),
845+
'<code>name</code>'
846+
);
819847
} elseif ( isset( $config['module'] ) && ( ! is_string( $config['module'] ) || '' === $config['module'] ) ) {
820-
$error = __( 'The `module` of a field collection must be the id of a script module.' );
848+
$error = sprintf(
849+
/* translators: %s: module */
850+
__( 'The %s of a field collection must be the id of a script module.' ),
851+
'<code>module</code>'
852+
);
821853
}
822854

823855
if ( null !== $error ) {
@@ -902,10 +934,12 @@ protected function read_collection_fields( $method, $directory ) {
902934
_doing_it_wrong(
903935
$method,
904936
sprintf(
905-
/* translators: 1: The name of a field collection. 2: Comma-separated list of folder names. */
906-
__( 'The `field.php` of a field must return an array, with a non-empty string `id` if it sets one. These fields of the field collection "%1$s" are skipped: %2$s.' ),
937+
/* translators: 1: The name of a field collection. 2: Comma-separated list of folder names. 3: field.php 4: id */
938+
__( 'The %3$s of a field must return an array, with a non-empty string %4$s if it sets one. These fields of the field collection "%1$s" are skipped: %2$s.' ),
907939
$collection,
908-
implode( ', ', $invalid )
940+
implode( ', ', $invalid ),
941+
'<code>field.php</code>',
942+
'<code>id</code>'
909943
),
910944
'7.2.0'
911945
);

‎src/wp-includes/rest-api/endpoints/class-wp-rest-entity-fields-controller.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,11 @@ protected function get_field_schema() {
279279
'type' => 'string',
280280
),
281281
'origin' => array(
282-
'description' => __( 'Who registered and updated the field: `core`, or the slug of a plugin or theme.' ),
282+
'description' => sprintf(
283+
/* translators: %s: core */
284+
__( 'Who registered and updated the field: %s, or the slug of a plugin or theme.' ),
285+
'core'
286+
),
283287
'type' => 'object',
284288
'properties' => array(
285289
'registeredBy' => array(

0 commit comments

Comments
 (0)