Skip to content

Commit

Permalink
Make a11y string properly localizable (#15161)
Browse files Browse the repository at this point in the history
* Make a11y string properly localizable

* Remove extra . after the content

* Add `accessibility text` to the translators comment

* Fix the wrong parameter

* Change the position of translator comments
  • Loading branch information
swissspidy authored and pinarol committed Apr 25, 2019
1 parent 7fd6969 commit da09d36
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/block-library/src/heading/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { isEmpty } from 'lodash';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import { RichText, BlockControls } from '@wordpress/block-editor';
import { createBlock } from '@wordpress/blocks';
Expand Down Expand Up @@ -98,13 +98,23 @@ class HeadingEdit extends Component {

const tagName = 'h' + level;

const accessibilityLabelLevel = __( 'level' ) + ' ' + level + __( '.' );
const accessibilityLabelContent = isEmpty( content ) ? __( 'Empty' ) : this.plainTextContent( content );

return (
<View
accessible={ ! this.props.isSelected }
accessibilityLabel={ __( 'Heading block' ) + __( '.' ) + ' ' + accessibilityLabelLevel + ' ' + accessibilityLabelContent }
accessibilityLabel={
isEmpty( content ) ?
sprintf(
/* translators: accessibility text. %s: heading level. */
__( 'Heading block. Level %s. Empty.' ),
level
) :
sprintf(
/* translators: accessibility text. 1: heading level. 2: heading content. */
__( 'Heading block. Level %1$s. %2$s' ),
level,
this.plainTextContent( content )
)
}
onAccessibilityTap={ this.props.onFocus }
>
<BlockControls>
Expand Down

0 comments on commit da09d36

Please sign in to comment.