From 1ffedef81e0a6bfe830d4783361e27aeef2745ba Mon Sep 17 00:00:00 2001 From: Christopher Reece Date: Tue, 21 Jan 2020 09:03:55 +0900 Subject: [PATCH] Added conditions and new translation strings for BlockMover (#19757) * Added conditions and new translation strings for BlockMover * Moved translator comments into sprintf function --- .../block-mover/mover-description.js | 139 ++++++++++++++---- 1 file changed, 111 insertions(+), 28 deletions(-) diff --git a/packages/block-editor/src/components/block-mover/mover-description.js b/packages/block-editor/src/components/block-mover/mover-description.js index d9a62de176d82..cb0203f8c60cf 100644 --- a/packages/block-editor/src/components/block-mover/mover-description.js +++ b/packages/block-editor/src/components/block-mover/mover-description.js @@ -49,47 +49,130 @@ export function getBlockMoverDescription( selectedCount, type, firstIndex, isFir if ( dir > 0 && ! isLast ) { // moving down - return sprintf( - // translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: Direction of movement ( up, down, left, right ), 4: New position - __( 'Move %1$s block from position %2$d %3$s to position %4$d' ), - type, - position, - getMovementDirection( 'down' ), - ( position + 1 ), - ); + const movementDirection = getMovementDirection( 'down' ); + + if ( movementDirection === 'down' ) { + return sprintf( + // translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position + __( 'Move %1$s block from position %2$d down to position %3$d' ), + type, + position, + ( position + 1 ), + ); + } + + if ( movementDirection === 'left' ) { + return sprintf( + // translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position + __( 'Move %1$s block from position %2$d left to position %3$d' ), + type, + position, + ( position + 1 ), + ); + } + + if ( movementDirection === 'right' ) { + return sprintf( + // translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position + __( 'Move %1$s block from position %2$d right to position %3$d' ), + type, + position, + ( position + 1 ), + ); + } } if ( dir > 0 && isLast ) { // moving down, and is the last item - // translators: 1: Type of block (i.e. Text, Image etc), 2: Direction of movement ( up, down, left, right ) - return sprintf( - __( 'Block %1$s is at the end of the content and can’t be moved %2$s' ), - type, - getMovementDirection( 'down' ), + const movementDirection = getMovementDirection( 'down' ); - ); + if ( movementDirection === 'down' ) { + return sprintf( + // translators: 1: Type of block (i.e. Text, Image etc) + __( 'Block %1$s is at the end of the content and can’t be moved down' ), + type, + ); + } + + if ( movementDirection === 'left' ) { + return sprintf( + // translators: 1: Type of block (i.e. Text, Image etc) + __( 'Block %1$s is at the end of the content and can’t be moved left' ), + type, + ); + } + + if ( movementDirection === 'right' ) { + return sprintf( + // translators: 1: Type of block (i.e. Text, Image etc) + __( 'Block %1$s is at the end of the content and can’t be moved right' ), + type, + ); + } } if ( dir < 0 && ! isFirst ) { // moving up - return sprintf( - // translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: Direction of movement ( up, down, left, right ), 4: New position - __( 'Move %1$s block from position %2$d %3$s to position %4$d' ), - type, - position, - getMovementDirection( 'up' ), - ( position - 1 ), - ); + const movementDirection = getMovementDirection( 'up' ); + + if ( movementDirection === 'up' ) { + return sprintf( + // translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position + __( 'Move %1$s block from position %2$d up to position %3$d' ), + type, + position, + ( position - 1 ), + ); + } + + if ( movementDirection === 'left' ) { + return sprintf( + // translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position + __( 'Move %1$s block from position %2$d left to position %3$d' ), + type, + position, + ( position - 1 ), + ); + } + + if ( movementDirection === 'right' ) { + return sprintf( + // translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position + __( 'Move %1$s block from position %2$d right to position %3$d' ), + type, + position, + ( position - 1 ), + ); + } } if ( dir < 0 && isFirst ) { // moving up, and is the first item - // translators: 1: Type of block (i.e. Text, Image etc), 2: Direction of movement ( up, down, left, right ) - return sprintf( - __( 'Block %1$s is at the beginning of the content and can’t be moved %2$s' ), - type, - getMovementDirection( 'up' ), - ); + const movementDirection = getMovementDirection( 'up' ); + + if ( movementDirection === 'up' ) { + return sprintf( + // translators: 1: Type of block (i.e. Text, Image etc) + __( 'Block %1$s is at the beginning of the content and can’t be moved up' ), + type, + ); + } + + if ( movementDirection === 'left' ) { + return sprintf( + // translators: 1: Type of block (i.e. Text, Image etc) + __( 'Block %1$s is at the beginning of the content and can’t be moved left' ), + type, + ); + } + + if ( movementDirection === 'right' ) { + return sprintf( + // translators: 1: Type of block (i.e. Text, Image etc) + __( 'Block %1$s is at the beginning of the content and can’t be moved right' ), + type, + ); + } } }