Skip to content

Commit

Permalink
[Mobile]Update string concatenation for accessibility labels (#15181)
Browse files Browse the repository at this point in the history
* Make accessibility labels properly localizable

* Fix indentation

* Fix image block accessibility labels
  • Loading branch information
pinarol authored and hypest committed May 2, 2019
1 parent f70fceb commit 5a09c65
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { View, Text, TouchableWithoutFeedback } from 'react-native';
/**
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';
import { Dashicon } from '@wordpress/components';

/**
Expand All @@ -17,7 +17,8 @@ import styles from './styles.scss';
function MediaPlaceholder( props ) {
return (
<TouchableWithoutFeedback
accessibilityLabel={ sprintf( '%s%s %s', __( 'Image block' ), __( '.' ), __( 'Empty' ) ) }
/* translators: accessibility text for the Image block empty state */
accessibilityLabel={ __( 'Image block. Empty' ) }
accessibilityRole={ 'button' }
accessibilityHint={ __( 'Double tap to select an image' ) }
onPress={ props.onMediaOptionsPressed }
Expand Down
21 changes: 18 additions & 3 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
BottomSheet,
Picker,
} from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { isURL } from '@wordpress/url';
import { doAction, hasAction } from '@wordpress/hooks';

Expand Down Expand Up @@ -331,7 +331,13 @@ class ImageEdit extends React.Component {
return (
<TouchableWithoutFeedback
accessible={ ! isSelected }
accessibilityLabel={ __( 'Image block' ) + __( '.' ) + ' ' + alt + __( '.' ) + ' ' + caption }

accessibilityLabel={ sprintf(
/* translators: accessibility text. 1: image alt text. 2: image caption. */
__( 'Image block. %1$s. %2$s' ),
alt,
caption
) }
accessibilityRole={ 'button' }
onPress={ this.onImagePressed }
disabled={ ! isSelected }
Expand Down Expand Up @@ -395,7 +401,16 @@ class ImageEdit extends React.Component {
<View
style={ { padding: 12, flex: 1 } }
accessible={ true }
accessibilityLabel={ __( 'Image caption' ) + __( '.' ) + ' ' + ( isEmpty( caption ) ? __( 'Empty' ) : caption ) }
accessibilityLabel={
isEmpty( caption ) ?
/* translators: accessibility text. Empty image caption. */
__( 'Image caption. Empty' ) :
sprintf(
/* translators: accessibility text. %s: image caption. */
__( 'Image caption. %s' ),
caption
)
}
accessibilityRole={ 'button' }
>
<TextInput
Expand Down
8 changes: 7 additions & 1 deletion packages/block-library/src/nextpage/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ export default function NextPageEdit( { attributes, isSelected, onFocus } ) {
return (
<View
accessible
accessibilityLabel={ sprintf( '%s%s %s', __( 'Page break block' ), __( '.' ), accessibilityTitle ) }
accessibilityLabel={
sprintf(
/* translators: accessibility text. %s: Page break text. */
__( 'Page break block. %s' ),
accessibilityTitle
)
}
accessibilityStates={ accessibilityState }
onAccessibilityTap={ onFocus }
>
Expand Down
13 changes: 11 additions & 2 deletions packages/block-library/src/paragraph/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isEmpty } from 'lodash';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import { createBlock } from '@wordpress/blocks';
import { RichText } from '@wordpress/block-editor';
Expand Down Expand Up @@ -107,7 +107,16 @@ class ParagraphEdit extends Component {
return (
<View
accessible={ ! this.props.isSelected }
accessibilityLabel={ __( 'Paragraph block' ) + __( '.' ) + ' ' + ( isEmpty( content ) ? __( 'Empty' ) : this.plainTextContent( content ) ) }
accessibilityLabel={
isEmpty( content ) ?
/* translators: accessibility text. empty paragraph block. */
__( 'Paragraph block. Empty' ) :
sprintf(
/* translators: accessibility text. %s: text content of the paragraph block. */
__( 'Paragraph block. %s' ),
this.plainTextContent( content )
)
}
onAccessibilityTap={ this.props.onFocus }
>
<RichText
Expand Down
11 changes: 10 additions & 1 deletion packages/editor/src/components/post-title/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,16 @@ class PostTitle extends Component {
<View
style={ [ styles.titleContainer, borderStyle, { borderColor } ] }
accessible={ ! this.state.isSelected }
accessibilityLabel={ sprintf( '%s%s %s', __( 'Post title' ), __( '.' ), ( isEmpty( title ) ? __( 'Empty' ) : title ) ) }
accessibilityLabel={
isEmpty( title ) ?
/* translators: accessibility text. empty post title. */
__( 'Post title. Empty' ) :
sprintf(
/* translators: accessibility text. %s: text content of the post title. */
__( 'Post title. %s' ),
title
)
}
>
<RichText
tagName={ 'p' }
Expand Down

0 comments on commit 5a09c65

Please sign in to comment.