Skip to content

Commit d6cc73e

Browse files
committed
Fix 'Link to post' label
1 parent 08d3e41 commit d6cc73e

File tree

1 file changed

+20
-8
lines changed
  • packages/block-library/src/post-date

1 file changed

+20
-8
lines changed

packages/block-library/src/post-date/edit.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import classnames from 'classnames';
66
/**
77
* WordPress dependencies
88
*/
9-
import { useEntityProp } from '@wordpress/core-data';
9+
import { useEntityProp, store as coreStore } from '@wordpress/core-data';
1010
import { useRef } from '@wordpress/element';
1111
import {
1212
dateI18n,
@@ -30,10 +30,11 @@ import {
3030
import { __, sprintf } from '@wordpress/i18n';
3131
import { edit } from '@wordpress/icons';
3232
import { DOWN } from '@wordpress/keycodes';
33+
import { useSelect } from '@wordpress/data';
3334

3435
export default function PostDateEdit( {
3536
attributes: { textAlign, format, isLink },
36-
context: { postId, postType, queryId },
37+
context: { postId, postType: postTypeSlug, queryId },
3738
setAttributes,
3839
} ) {
3940
const blockProps = useBlockProps( {
@@ -56,10 +57,17 @@ export default function PostDateEdit( {
5657
);
5758
const [ date, setDate ] = useEntityProp(
5859
'postType',
59-
postType,
60+
postTypeSlug,
6061
'date',
6162
postId
6263
);
64+
const postType = useSelect(
65+
( select ) =>
66+
postTypeSlug
67+
? select( coreStore ).getPostType( postTypeSlug )
68+
: null,
69+
[ postTypeSlug ]
70+
);
6371

6472
let postDate = date ? (
6573
<time dateTime={ dateI18n( 'c', date ) } ref={ timeRef }>
@@ -134,11 +142,15 @@ export default function PostDateEdit( {
134142
}
135143
/>
136144
<ToggleControl
137-
label={ sprintf(
138-
// translators: %s: Name of the post type e.g: "post".
139-
__( 'Link to %s' ),
140-
postType
141-
) }
145+
label={
146+
postType?.labels.singular_name
147+
? sprintf(
148+
// translators: %s: Name of the post type e.g: "post".
149+
__( 'Link to %s' ),
150+
postType.labels.singular_name.toLowerCase()
151+
)
152+
: __( 'Link to post' )
153+
}
142154
onChange={ () => setAttributes( { isLink: ! isLink } ) }
143155
checked={ isLink }
144156
/>

0 commit comments

Comments
 (0)