Skip to content

Commit

Permalink
Extensions: drop i18n wrapper (#11743)
Browse files Browse the repository at this point in the history
* Remove wrapper on i18n functions, update imports
* Run codemod to add jetpack textdomain
* Manually add jetpack textdomain to extensions/blocks/map/component.js
  • Loading branch information
sirreal authored and ockham committed Apr 2, 2019
1 parent 858b174 commit 795f8da
Show file tree
Hide file tree
Showing 70 changed files with 572 additions and 631 deletions.
24 changes: 12 additions & 12 deletions extensions/blocks/business-hours/components/day-edit.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';
import classNames from 'classnames';
import { __ } from '@wordpress/i18n';
import { Component, Fragment } from '@wordpress/element';
import { IconButton, TextControl, ToggleControl } from '@wordpress/components';
import classNames from 'classnames';

/**
* Internal dependencies
*/
import { __ } from '../../../utils/i18n';
import { isEmpty } from 'lodash';

const defaultOpen = '09:00';
const defaultClose = '17:00';
Expand All @@ -27,7 +23,7 @@ class DayEdit extends Component {
<div className={ classNames( day.name, 'business-hours__hours' ) }>
<TextControl
type="time"
label={ __( 'Opening' ) }
label={ __( 'Opening', 'jetpack' ) }
value={ opening }
className="business-hours__open"
placeholder={ defaultOpen }
Expand All @@ -37,7 +33,7 @@ class DayEdit extends Component {
/>
<TextControl
type="time"
label={ __( 'Closing' ) }
label={ __( 'Closing', 'jetpack' ) }
value={ closing }
className="business-hours__close"
placeholder={ defaultClose }
Expand All @@ -63,8 +59,12 @@ class DayEdit extends Component {
<div className="business-hours__row business-hours-row__add">
<div className={ classNames( day.name, 'business-hours__day' ) }>&nbsp;</div>
<div className={ classNames( day.name, 'business-hours__hours' ) }>
<IconButton isLink label={ __( 'Add Hours' ) } onClick={ this.addInterval }>
{ __( 'Add Hours' ) }
<IconButton
isLink
label={ __( 'Add Hours', 'jetpack' ) }
onClick={ this.addInterval }
>
{ __( 'Add Hours', 'jetpack' ) }
</IconButton>
</div>
<div className="business-hours__remove">&nbsp;</div>
Expand Down Expand Up @@ -170,7 +170,7 @@ class DayEdit extends Component {
<Fragment>
<span className="business-hours__day-name">{ localization.days[ day.name ] }</span>
<ToggleControl
label={ this.isClosed() ? __( 'Closed' ) : __( 'Open' ) }
label={ this.isClosed() ? __( 'Closed', 'jetpack' ) : __( 'Open', 'jetpack' ) }
checked={ ! this.isClosed() }
onChange={ this.toggleClosed }
/>
Expand Down
11 changes: 3 additions & 8 deletions extensions/blocks/business-hours/components/day-preview.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
/**
* External dependencies
*/
import { _x, sprintf } from '@wordpress/i18n';
import { Component, Fragment } from '@wordpress/element';
import { date } from '@wordpress/date';
import { isEmpty } from 'lodash';
import { sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { _x } from '../../../utils/i18n';

class DayPreview extends Component {
formatTime( time ) {
Expand All @@ -28,7 +23,7 @@ class DayPreview extends Component {
return (
<dd key={ key }>
{ sprintf(
_x( 'From %s to %s', 'from business opening hour to closing hour' ),
_x( 'From %s to %s', 'from business opening hour to closing hour', 'jetpack' ),
this.formatTime( interval.opening ),
this.formatTime( interval.closing )
) }
Expand All @@ -46,7 +41,7 @@ class DayPreview extends Component {
<Fragment>
<dt className={ day.name }>{ localization.days[ day.name ] }</dt>
{ isEmpty( hours ) ? (
<dd>{ _x( 'Closed', 'business is closed on a full day' ) }</dd>
<dd>{ _x( 'Closed', 'business is closed on a full day', 'jetpack' ) }</dd>
) : (
hours.map( this.renderInterval )
) }
Expand Down
24 changes: 12 additions & 12 deletions extensions/blocks/business-hours/edit.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
/**
* External dependencies
*/
import { BlockIcon } from '@wordpress/editor';
import { Component } from '@wordpress/element';
import { Placeholder } from '@wordpress/components';
import apiFetch from '@wordpress/api-fetch';
import classNames from 'classnames';
import { __ } from '@wordpress/i18n';
import { __experimentalGetSettings } from '@wordpress/date';
import { BlockIcon } from '@wordpress/editor';
import { Component } from '@wordpress/element';
import { Placeholder } from '@wordpress/components';

/**
* Internal dependencies
*/
import DayEdit from './components/day-edit';
import DayPreview from './components/day-preview';
import { icon } from '.';
import { __ } from '../../utils/i18n';

const defaultLocalization = {
days: {
Sun: __( 'Sunday' ),
Mon: __( 'Monday' ),
Tue: __( 'Tuesday' ),
Wed: __( 'Wednesday' ),
Thu: __( 'Thursday' ),
Fri: __( 'Friday' ),
Sat: __( 'Saturday' ),
Sun: __( 'Sunday', 'jetpack' ),
Mon: __( 'Monday', 'jetpack' ),
Tue: __( 'Tuesday', 'jetpack' ),
Wed: __( 'Wednesday', 'jetpack' ),
Thu: __( 'Thursday', 'jetpack' ),
Fri: __( 'Friday', 'jetpack' ),
Sat: __( 'Saturday', 'jetpack' ),
},
startOfWeek: 0,
};
Expand Down Expand Up @@ -63,7 +63,7 @@ class BusinessHours extends Component {
return (
<Placeholder
icon={ <BlockIcon icon={ icon } /> }
label={ __( 'Loading business hours' ) }
label={ __( 'Loading business hours', 'jetpack' ) }
/>
);
}
Expand Down
15 changes: 7 additions & 8 deletions extensions/blocks/business-hours/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/**
* External dependencies
*/
import { __, _x } from '@wordpress/i18n';
import { Path } from '@wordpress/components';

/**
* Internal dependencies
*/
import { __, _x } from '../../utils/i18n';
import renderMaterialIcon from '../../utils/render-material-icon';

import './editor.scss';
import BusinessHours from './edit';
import renderMaterialIcon from '../../utils/render-material-icon';

/**
* Block Registrations:
Expand All @@ -23,17 +22,17 @@ export const icon = renderMaterialIcon(
);

export const settings = {
title: __( 'Business Hours' ),
description: __( 'Display opening hours for your business.' ),
title: __( 'Business Hours', 'jetpack' ),
description: __( 'Display opening hours for your business.', 'jetpack' ),
icon,
category: 'jetpack',
supports: {
html: true,
},
keywords: [
_x( 'opening hours', 'block search term' ),
_x( 'closing time', 'block search term' ),
_x( 'schedule', 'block search term' ),
_x( 'opening hours', 'block search term', 'jetpack' ),
_x( 'closing time', 'block search term', 'jetpack' ),
_x( 'schedule', 'block search term', 'jetpack' ),
],
attributes: {
days: {
Expand Down
43 changes: 24 additions & 19 deletions extensions/blocks/contact-form/components/jetpack-contact-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
* External dependencies
*/
import classnames from 'classnames';
import { Button, PanelBody, Placeholder, TextControl, Path } from '@wordpress/components';
import { InnerBlocks, InspectorControls } from '@wordpress/editor';
import { Component, Fragment } from '@wordpress/element';
import { sprintf } from '@wordpress/i18n';
import emailValidator from 'email-validator';
import { __, sprintf } from '@wordpress/i18n';
import { Button, PanelBody, Path, Placeholder, TextControl } from '@wordpress/components';
import { Component, Fragment } from '@wordpress/element';
import { compose, withInstanceId } from '@wordpress/compose';
import { InnerBlocks, InspectorControls } from '@wordpress/editor';

/**
* Internal dependencies
*/
import { __ } from '../../../utils/i18n';
import HelpMessage from '../../../shared/help-message';
import renderMaterialIcon from '../../../utils/render-material-icon';
import SubmitButton from '../../../utils/submit-button';
import HelpMessage from '../../../shared/help-message';

const ALLOWED_BLOCKS = [
'jetpack/markdown',
'core/paragraph',
Expand Down Expand Up @@ -64,12 +64,13 @@ class JetpackContactForm extends Component {

getIntroMessage() {
return __(
'You’ll receive an email notification each time someone fills out the form. Where should it go, and what should the subject line be?'
'You’ll receive an email notification each time someone fills out the form. Where should it go, and what should the subject line be?',
'jetpack'
);
}

getEmailHelpMessage() {
return __( 'You can enter multiple email addresses separated by commas.' );
return __( 'You can enter multiple email addresses separated by commas.', 'jetpack' );
}

onChangeSubject( subject ) {
Expand Down Expand Up @@ -127,20 +128,23 @@ class JetpackContactForm extends Component {
if ( errors ) {
if ( errors.length === 1 ) {
if ( errors[ 0 ] && errors[ 0 ].email ) {
return sprintf( __( '%s is not a valid email address.' ), errors[ 0 ].email );
return sprintf( __( '%s is not a valid email address.', 'jetpack' ), errors[ 0 ].email );
}
return errors[ 0 ];
}

if ( errors.length === 2 ) {
return sprintf(
__( '%s and %s are not a valid email address.' ),
__( '%s and %s are not a valid email address.', 'jetpack' ),
errors[ 0 ].email,
errors[ 1 ].email
);
}
const inValidEmails = errors.map( error => error.email );
return sprintf( __( '%s are not a valid email address.' ), inValidEmails.join( ', ' ) );
return sprintf(
__( '%s are not a valid email address.', 'jetpack' ),
inValidEmails.join( ', ' )
);
}
return null;
}
Expand All @@ -162,8 +166,8 @@ class JetpackContactForm extends Component {
aria-describedby={ `contact-form-${ instanceId }-email-${
this.hasEmailError() ? 'error' : 'help'
}` }
label={ __( 'Email address' ) }
placeholder={ __( '[email protected]' ) }
label={ __( 'Email address', 'jetpack' ) }
placeholder={ __( '[email protected]', 'jetpack' ) }
onKeyDown={ this.preventEnterSubmittion }
value={ to }
onBlur={ this.onBlurTo }
Expand All @@ -177,9 +181,9 @@ class JetpackContactForm extends Component {
</HelpMessage>

<TextControl
label={ __( 'Email subject line' ) }
label={ __( 'Email subject line', 'jetpack' ) }
value={ subject }
placeholder={ __( "Let's work together" ) }
placeholder={ __( "Let's work together", 'jetpack' ) }
onChange={ this.onChangeSubject }
/>
</Fragment>
Expand All @@ -201,14 +205,14 @@ class JetpackContactForm extends Component {
return (
<Fragment>
<InspectorControls>
<PanelBody title={ __( 'Email feedback settings' ) }>
<PanelBody title={ __( 'Email feedback settings', 'jetpack' ) }>
{ this.renderToAndSubjectFields() }
</PanelBody>
</InspectorControls>
<div className={ formClassnames }>
{ ! hasFormSettingsSet && (
<Placeholder
label={ __( 'Form' ) }
label={ __( 'Form', 'jetpack' ) }
icon={ renderMaterialIcon(
<Path d="M13 7.5h5v2h-5zm0 7h5v2h-5zM19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14zM11 6H6v5h5V6zm-1 4H7V7h3v3zm1 3H6v5h5v-5zm-1 4H7v-3h3v3z" />
) }
Expand All @@ -218,12 +222,13 @@ class JetpackContactForm extends Component {
{ this.renderToAndSubjectFields() }
<p className="jetpack-contact-form__intro-message">
{ __(
'(If you leave these blank, notifications will go to the author with the post or page title as the subject line.)'
'(If you leave these blank, notifications will go to the author with the post or page title as the subject line.)',
'jetpack'
) }
</p>
<div className="jetpack-contact-form__create">
<Button isPrimary type="submit" disabled={ this.hasEmailError() }>
{ __( 'Add form' ) }
{ __( 'Add form', 'jetpack' ) }
</Button>
</div>
</form>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { BaseControl, PanelBody, TextControl, ToggleControl } from '@wordpress/components';
import { Fragment } from '@wordpress/element';
import { withInstanceId } from '@wordpress/compose';
import { InspectorControls } from '@wordpress/editor';
import { withInstanceId } from '@wordpress/compose';

/**
* Internal dependencies
*/
import JetpackFieldLabel from './jetpack-field-label';
import { __ } from '../../../utils/i18n';

const JetpackFieldCheckbox = ( {
instanceId,
Expand Down Expand Up @@ -40,14 +40,14 @@ const JetpackFieldCheckbox = ( {
isSelected={ isSelected }
/>
<InspectorControls>
<PanelBody title={ __( 'Field Settings' ) }>
<PanelBody title={ __( 'Field Settings', 'jetpack' ) }>
<ToggleControl
label={ __( 'Default Checked State' ) }
label={ __( 'Default Checked State', 'jetpack' ) }
checked={ defaultValue }
onChange={ value => setAttributes( { defaultValue: value } ) }
/>
<TextControl
label={ __( 'ID' ) }
label={ __( 'ID', 'jetpack' ) }
value={ id }
onChange={ value => setAttributes( { id: value } ) }
/>
Expand Down
14 changes: 6 additions & 8 deletions extensions/blocks/contact-form/components/jetpack-field-label.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { PlainText } from '@wordpress/editor';
import { ToggleControl } from '@wordpress/components';

/**
* Internal dependencies
*/
import { __ } from '../../../utils/i18n';

const JetpackFieldLabel = ( { setAttributes, label, resetFocus, isSelected, required } ) => {
return (
<div className="jetpack-field-label">
Expand All @@ -19,17 +15,19 @@ const JetpackFieldLabel = ( { setAttributes, label, resetFocus, isSelected, requ
resetFocus && resetFocus();
setAttributes( { label: value } );
} }
placeholder={ __( 'Write label…' ) }
placeholder={ __( 'Write label…', 'jetpack' ) }
/>
{ isSelected && (
<ToggleControl
label={ __( 'Required' ) }
label={ __( 'Required', 'jetpack' ) }
className="jetpack-field-label__required"
checked={ required }
onChange={ value => setAttributes( { required: value } ) }
/>
) }
{ ! isSelected && required && <span className="required">{ __( '(required)' ) }</span> }
{ ! isSelected && required && (
<span className="required">{ __( '(required)', 'jetpack' ) }</span>
) }
</div>
);
};
Expand Down
Loading

0 comments on commit 795f8da

Please sign in to comment.