UNPKG

@gechiui/block-editor

Version:
166 lines (138 loc) 6.47 kB
/** * GeChiUI dependencies */ import { __, _n, sprintf, isRTL } from '@gechiui/i18n'; /** * Return a label for the block movement controls depending on block position. * * @param {number} selectedCount Number of blocks selected. * @param {string} type Block type - in the case of a single block, should * define its 'type'. I.e. 'Text', 'Heading', 'Image' etc. * @param {number} firstIndex The index (position - 1) of the first block selected. * @param {boolean} isFirst This is the first block. * @param {boolean} isLast This is the last block. * @param {number} dir Direction of movement (> 0 is considered to be going * down, < 0 is up). * @param {string} orientation The orientation of the block movers, vertical or * horizontal. * * @return {string} Label for the block movement controls. */ export function getBlockMoverDescription(selectedCount, type, firstIndex, isFirst, isLast, dir, orientation) { const position = firstIndex + 1; const getMovementDirection = moveDirection => { if (moveDirection === 'up') { if (orientation === 'horizontal') { return isRTL() ? 'right' : 'left'; } return 'up'; } else if (moveDirection === 'down') { if (orientation === 'horizontal') { return isRTL() ? 'left' : 'right'; } return 'down'; } return null; }; if (selectedCount > 1) { return getMultiBlockMoverDescription(selectedCount, firstIndex, isFirst, isLast, dir); } if (isFirst && isLast) { return sprintf( // translators: %s: Type of block (i.e. Text, Image etc) __('区块%s是唯一的区块,不能被移动'), type); } if (dir > 0 && !isLast) { // moving down 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 __('将区块%1$s从位置%2$d下移到位置%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 __('将区块%1$s从位置%2$d左移至位置%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 __('将区块%1$s从位置%2$d右移至位置%3$d'), type, position, position + 1); } } if (dir > 0 && isLast) { // moving down, and is the last item const movementDirection = getMovementDirection('down'); if (movementDirection === 'down') { return sprintf( // translators: 1: Type of block (i.e. Text, Image etc) __('区块%1$s已在内容最末,不能被下移'), type); } if (movementDirection === 'left') { return sprintf( // translators: 1: Type of block (i.e. Text, Image etc) __('区块%1$s已在内容最末,不能被左移'), type); } if (movementDirection === 'right') { return sprintf( // translators: 1: Type of block (i.e. Text, Image etc) __('区块%1$s已在内容最末,不能被右移'), type); } } if (dir < 0 && !isFirst) { // moving up 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 __('将区块%1$s从位置%2$d上移到位置%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 __('将区块%1$s从位置%2$d左移至位置%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 __('将区块%1$s从位置%2$d右移至位置%3$d'), type, position, position - 1); } } if (dir < 0 && isFirst) { // moving up, and is the first item const movementDirection = getMovementDirection('up'); if (movementDirection === 'up') { return sprintf( // translators: 1: Type of block (i.e. Text, Image etc) __('区块%1$s已在内容最始,不能被上移'), type); } if (movementDirection === 'left') { return sprintf( // translators: 1: Type of block (i.e. Text, Image etc) __('区块%1$s已在内容最始,不能被左移'), type); } if (movementDirection === 'right') { return sprintf( // translators: 1: Type of block (i.e. Text, Image etc) __('区块%1$s已在内容最始,不能被右移'), type); } } } /** * Return a label for the block movement controls depending on block position. * * @param {number} selectedCount Number of blocks selected. * @param {number} firstIndex The index (position - 1) of the first block selected. * @param {boolean} isFirst This is the first block. * @param {boolean} isLast This is the last block. * @param {number} dir Direction of movement (> 0 is considered to be going * down, < 0 is up). * * @return {string} Label for the block movement controls. */ export function getMultiBlockMoverDescription(selectedCount, firstIndex, isFirst, isLast, dir) { const position = firstIndex + 1; if (dir < 0 && isFirst) { return __('区块已在最顶,不能被上移'); } if (dir > 0 && isLast) { return __('区块已在最底,不能被下移'); } if (dir < 0 && !isFirst) { return sprintf( // translators: 1: Number of selected blocks, 2: Position of selected blocks _n('将%1$d个区块从位置%2$d上移一位', 'Move %1$d blocks from position %2$d up by one place', selectedCount), selectedCount, position); } if (dir > 0 && !isLast) { return sprintf( // translators: 1: Number of selected blocks, 2: Position of selected blocks _n('将%1$d个区块从位置%2$d下移一位', 'Move %1$d blocks from position %2$d down by one place', selectedCount), selectedCount, position); } } //# sourceMappingURL=mover-description.js.map