Skip to content

Commit

Permalink
use sprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Dec 16, 2022
1 parent a393ce8 commit 3ae0ece
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function MediaList( {
>
{ mediaList.map( ( media, index ) => (
<MediaPreview
key={ media.id || index }
key={ media.id || media.sourceId || index }
media={ media }
mediaType={ mediaType }
onClick={ onPreviewClick }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { resolveSelect } from '@wordpress/data';
import { decodeEntities } from '@wordpress/html-entities';

Expand Down Expand Up @@ -38,16 +38,24 @@ const getOpenvereLicense = (
licenseName
);
}
// TODO: add translators comment.
const markedLicence = isPublicDomainMark
? __( 'is marked with' )
: __( 'is licensed under' );
return `${ markedLicence } ${ license }`;
? sprintf(
/* translators: %s: Name of the media's license (ex. 'CC0 1.0'). */
__( 'is marked with %s' ),
license
)
: sprintf(
/* translators: %s: Name of the media's license (ex. 'CC BY-ND 2.0'). */
__( 'is licensed under %s' ),
license
);
return markedLicence;
};

const getOpenverseCaption = ( item ) => {
const {
title = __( 'This work' ), // TODO: add translators comment.
/* translators: Openverse default media item title in the block inserter's media list. (ex. 'This work by {creator} is marked with CC0 1.0'). */
title = __( 'This work' ),
foreign_landing_url: foreignLandingUrl,
creator,
creator_url: creatorUrl,
Expand All @@ -68,7 +76,11 @@ const getOpenverseCaption = ( item ) => {
if ( creatorUrl ) {
_creator = getExternalLink( creatorUrl, creator );
}
_creator = ` ${ __( 'by' ) } ${ _creator }`; // TODO: add translators comment.
_creator = sprintf(
/* translators: %s: Name of the media's creator. */
__( ' by %s' ),
_creator
);
const caption = `"${ _title }" ${ _creator } ${ fullLicense }.`;
return caption.replace( /\s{2}/g, ' ' );
};
Expand Down
26 changes: 19 additions & 7 deletions packages/editor/src/components/media-categories/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { resolveSelect } from '@wordpress/data';
import { decodeEntities } from '@wordpress/html-entities';

Expand Down Expand Up @@ -38,16 +38,24 @@ const getOpenvereLicense = (
licenseName
);
}
// TODO: add translators comment.
const markedLicence = isPublicDomainMark
? __( 'is marked with' )
: __( 'is licensed under' );
return `${ markedLicence } ${ license }`;
? sprintf(
/* translators: %s: Name of the media's license (ex. 'CC0 1.0'). */
__( 'is marked with %s' ),
license
)
: sprintf(
/* translators: %s: Name of the media's license (ex. 'CC BY-ND 2.0'). */
__( 'is licensed under %s' ),
license
);
return markedLicence;
};

const getOpenverseCaption = ( item ) => {
const {
title = __( 'This work' ), // TODO: add translators comment.
/* translators: Openverse default media item title in the block inserter's media list. (ex. 'This work by {creator} is marked with CC0 1.0'). */
title = __( 'This work' ),
foreign_landing_url: foreignLandingUrl,
creator,
creator_url: creatorUrl,
Expand All @@ -68,7 +76,11 @@ const getOpenverseCaption = ( item ) => {
if ( creatorUrl ) {
_creator = getExternalLink( creatorUrl, creator );
}
_creator = ` ${ __( 'by' ) } ${ _creator }`; // TODO: add translators comment.
_creator = sprintf(
/* translators: %s: Name of the media's creator. */
__( ' by %s' ),
_creator
);
const caption = `"${ _title }" ${ _creator } ${ fullLicense }.`;
return caption.replace( /\s{2}/g, ' ' );
};
Expand Down

1 comment on commit 3ae0ece

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3713821695
📝 Reported issues:

Please sign in to comment.