Skip to content

Commit

Permalink
Add preference label to spoken message
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Feb 22, 2022
1 parent 62d5159 commit cfba431
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { MenuItem } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { check } from '@wordpress/icons';
import { speak } from '@wordpress/a11y';

Expand All @@ -28,9 +28,23 @@ export default function PreferenceToggleMenuItem( {
const { toggle } = useDispatch( preferencesStore );
const speakMessage = () => {
if ( isActive ) {
speak( messageDeactivated || __( 'Preference deactivated' ) );
const message =
messageDeactivated ||
sprintf(
/* translators: %s: preference name, e.g. 'Fullscreen mode' */
__( 'Preference deactivated - %s' ),
label
);
speak( message );
} else {
speak( messageActivated || __( 'Preference activated' ) );
const message =
messageActivated ||
sprintf(
/* translators: %s: preference name, e.g. 'Fullscreen mode' */
__( 'Preference activated - %s' ),
label
);
speak( message );
}
};

Expand Down

0 comments on commit cfba431

Please sign in to comment.