diff --git a/.babelrc b/.babelrc index 81d31b8c6b2..0c2178c17d0 100644 --- a/.babelrc +++ b/.babelrc @@ -14,6 +14,12 @@ { "pragma": "wp.element.createElement" } + ], + [ + "@wordpress/babel-plugin-makepot", + { + "output": "languages/amp-js.pot" + } ] ], "env": { diff --git a/.gitignore b/.gitignore index bc9d65fd9a4..016f1596590 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ node_modules wiki amp.zip **/*-compiled.js +languages/*.pot +languages/*.php diff --git a/Gruntfile.js b/Gruntfile.js index 33ba9d730a6..e4168fd9bee 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -42,7 +42,16 @@ module.exports = function( grunt ) { verify_matching_versions: { command: 'php bin/verify-version-consistency.php' }, - create_release_zip: { + webpack_production: { + command: 'cross-env BABEL_ENV=production webpack' + }, + pot_to_php: { + command: 'npm run pot-to-php' + }, + makepot: { + command: 'wp i18n make-pot .' + }, + create_build_zip: { command: 'if [ ! -e build ]; then echo "Run grunt build first."; exit 1; fi; if [ -e amp.zip ]; then rm amp.zip; fi; cd build; zip -r ../amp.zip .; cd ..; echo; echo "ZIP of build: $(pwd)/amp.zip"' } }, @@ -82,6 +91,8 @@ module.exports = function( grunt ) { spawnQueue = []; stdout = []; + grunt.task.run( 'shell:webpack_production' ); + spawnQueue.push( { cmd: 'git', @@ -100,12 +111,14 @@ module.exports = function( grunt ) { versionAppend = commitHash + '-' + new Date().toISOString().replace( /\.\d+/, '' ).replace( /-|:/g, '' ); paths = lsOutput.trim().split( /\n/ ).filter( function( file ) { - return ! /^(blocks|\.|bin|([^/]+)+\.(md|json|xml)|Gruntfile\.js|tests|wp-assets|dev-lib|readme\.md|composer\..*)/.test( file ); + return ! /^(blocks|\.|bin|([^/]+)+\.(md|json|xml)|Gruntfile\.js|tests|wp-assets|dev-lib|readme\.md|composer\..*|languages\/README.*)/.test( file ); } ); paths.push( 'vendor/autoload.php' ); paths.push( 'assets/js/*-compiled.js' ); paths.push( 'vendor/composer/**' ); paths.push( 'vendor/sabberworm/php-css-parser/lib/**' ); + paths.push( 'languages/amp-translations.php' ); + paths.push( 'languages/amp.pot' ); grunt.task.run( 'clean' ); grunt.config.set( 'copy', { @@ -137,8 +150,6 @@ module.exports = function( grunt ) { grunt.task.run( 'readme' ); grunt.task.run( 'copy' ); - grunt.task.run( 'shell:create_release_zip' ); - done(); } @@ -163,16 +174,21 @@ module.exports = function( grunt ) { doNext(); } ); - grunt.registerTask( 'create-release-zip', [ - 'build', - 'shell:create_release_zip' + grunt.registerTask( 'create-build-zip', [ + 'shell:create_build_zip' + ] ); + + grunt.registerTask( 'build-release', [ + 'shell:makepot', + 'shell:pot_to_php', + 'build' ] ); grunt.registerTask( 'deploy', [ - 'build', 'jshint', 'shell:phpunit', 'shell:verify_matching_versions', + 'build-release', 'wp_deploy' ] ); }; diff --git a/assets/js/amp-editor-blocks.js b/assets/js/amp-editor-blocks.js index 4dc2b106bb2..4308a572b41 100644 --- a/assets/js/amp-editor-blocks.js +++ b/assets/js/amp-editor-blocks.js @@ -15,7 +15,7 @@ var ampEditorBlocks = ( function() { // eslint-disable-line no-unused-vars ampLayoutOptions: [ { value: 'nodisplay', - label: __( 'No Display' ), + label: __( 'No Display', 'amp' ), notAvailable: [ 'core-embed/vimeo', 'core-embed/dailymotion', @@ -27,7 +27,7 @@ var ampEditorBlocks = ( function() { // eslint-disable-line no-unused-vars { // Not supported by amp-audio and amp-pixel. value: 'fixed', - label: __( 'Fixed' ), + label: __( 'Fixed', 'amp' ), notAvailable: [ 'core-embed/soundcloud' ] @@ -35,7 +35,7 @@ var ampEditorBlocks = ( function() { // eslint-disable-line no-unused-vars { // To ensure your AMP element displays, you must specify a width and height for the containing element. value: 'responsive', - label: __( 'Responsive' ), + label: __( 'Responsive', 'amp' ), notAvailable: [ 'core/audio', 'core-embed/soundcloud' @@ -43,12 +43,12 @@ var ampEditorBlocks = ( function() { // eslint-disable-line no-unused-vars }, { value: 'fixed-height', - label: __( 'Fixed height' ), + label: __( 'Fixed height', 'amp' ), notAvailable: [] }, { value: 'fill', - label: __( 'Fill' ), + label: __( 'Fill', 'amp' ), notAvailable: [ 'core/audio', 'core-embed/soundcloud' @@ -56,7 +56,7 @@ var ampEditorBlocks = ( function() { // eslint-disable-line no-unused-vars }, { value: 'flex-item', - label: __( 'Flex Item' ), + label: __( 'Flex Item', 'amp' ), notAvailable: [ 'core/audio', 'core-embed/soundcloud' @@ -65,7 +65,7 @@ var ampEditorBlocks = ( function() { // eslint-disable-line no-unused-vars { // Not supported by video. value: 'intrinsic', - label: __( 'Intrinsic' ), + label: __( 'Intrinsic', 'amp' ), notAvailable: [ 'core/audio', 'core-embed/youtube', @@ -132,7 +132,7 @@ var ampEditorBlocks = ( function() { // eslint-disable-line no-unused-vars var layoutOptions = [ { value: '', - label: __( 'Default' ) + label: __( 'Default', 'amp' ) } ]; @@ -328,15 +328,15 @@ var ampEditorBlocks = ( function() { // eslint-disable-line no-unused-vars SelectControl = wp.components.SelectControl, ToggleControl = wp.components.ToggleControl, PanelBody = wp.components.PanelBody, - label = __( 'AMP Layout' ); + label = __( 'AMP Layout', 'amp' ); if ( 'core/image' === name ) { - label = __( 'AMP Layout (modifies width/height)' ); + label = __( 'AMP Layout (modifies width/height)', 'amp' ); } return isSelected && ( el( InspectorControls, { key: 'inspector' }, - el( PanelBody, { title: __( 'AMP Settings' ) }, + el( PanelBody, { title: __( 'AMP Settings', 'amp' ) }, el( SelectControl, { label: label, value: ampLayout, @@ -349,7 +349,7 @@ var ampEditorBlocks = ( function() { // eslint-disable-line no-unused-vars } } ), el( ToggleControl, { - label: __( 'AMP loading indicator disabled' ), + label: __( 'AMP loading indicator disabled', 'amp' ), checked: ampNoLoading, onChange: function() { props.setAttributes( { ampNoLoading: ! ampNoLoading } ); @@ -507,7 +507,7 @@ var ampEditorBlocks = ( function() { // eslint-disable-line no-unused-vars if ( component.isGalleryShortcode( props.attributes ) ) { toggleControl = el( ToggleControl, { - label: __( 'Display as AMP carousel' ), + label: __( 'Display as AMP carousel', 'amp' ), checked: ampCarousel, onChange: function() { props.setAttributes( { ampCarousel: ! ampCarousel } ); @@ -515,7 +515,7 @@ var ampEditorBlocks = ( function() { // eslint-disable-line no-unused-vars } ); return isSelected && ( el( InspectorControls, { key: 'inspector' }, - el( PanelBody, { title: __( 'AMP Settings' ) }, + el( PanelBody, { title: __( 'AMP Settings', 'amp' ) }, toggleControl ) ) diff --git a/bin/deploy-travis-pantheon.sh b/bin/deploy-travis-pantheon.sh index 3d84d8e6e45..9450d5265f4 100755 --- a/bin/deploy-travis-pantheon.sh +++ b/bin/deploy-travis-pantheon.sh @@ -85,7 +85,7 @@ if [ ! -e node_modules/.bin ]; then npm install fi PATH="node_modules/.bin/:$PATH" -grunt build +npm run build rsync -avz --delete ./build/ "$repo_dir/wp-content/plugins/amp/" git --no-pager log -1 --format="Build AMP plugin at %h: %s" > /tmp/commit-message.txt diff --git a/blocks/amp-brid-player/index.js b/blocks/amp-brid-player/index.js index 3853b1c234a..510b734d3c6 100644 --- a/blocks/amp-brid-player/index.js +++ b/blocks/amp-brid-player/index.js @@ -19,12 +19,12 @@ const { export default registerBlockType( 'amp/amp-brid-player', { - title: __( 'AMP Brid Player' ), - description: __( 'Displays the Brid Player used in Brid.tv Video Platform.' ), + title: __( 'AMP Brid Player', 'amp' ), + description: __( 'Displays the Brid Player used in Brid.tv Video Platform.', 'amp' ), category: 'common', icon: 'embed-generic', keywords: [ - __( 'Embed' ) + __( 'Embed', 'amp' ) ], attributes: { @@ -63,12 +63,12 @@ export default registerBlockType( edit( { attributes, isSelected, setAttributes } ) { const { autoPlay, dataPartner, dataPlayer, dataVideo, dataPlaylist, dataOutstream, layout, height, width } = attributes; const ampLayoutOptions = [ - { value: 'responsive', label: __( 'Responsive' ) }, - { value: 'fixed-height', label: __( 'Fixed height' ) }, - { value: 'fixed', label: __( 'Fixed' ) }, - { value: 'fill', label: __( 'Fill' ) }, - { value: 'flex-item', label: __( 'Flex-item' ) }, - { value: 'nodisplay', label: __( 'No Display' ) } + { value: 'responsive', label: __( 'Responsive', 'amp' ) }, + { value: 'fixed-height', label: __( 'Fixed height', 'amp' ) }, + { value: 'fixed', label: __( 'Fixed', 'amp' ) }, + { value: 'fill', label: __( 'Fill', 'amp' ) }, + { value: 'flex-item', label: __( 'Flex-item', 'amp' ) }, + { value: 'nodisplay', label: __( 'No Display', 'amp' ) } ]; let url = false; @@ -80,52 +80,52 @@ export default registerBlockType( { isSelected && ( - + ( setAttributes( { dataPartner: value } ) ) } /> ( setAttributes( { dataPlayer: value } ) ) } /> ( setAttributes( { dataVideo: value } ) ) } /> ( setAttributes( { dataOutstream: value } ) ) } /> ( setAttributes( { dataPlaylist: value } ) ) } /> ( setAttributes( { autoPlay: ! autoPlay } ) ) } /> ( setAttributes( { layout: value } ) ) } /> ( setAttributes( { width: value } ) ) } /> ( setAttributes( { height: value } ) ) } /> @@ -135,17 +135,17 @@ export default registerBlockType( } { url && ( - +

{ url }

-

{ __( 'Previews for this are unavailable in the editor, sorry!' ) }

+

{ __( 'Previews for this are unavailable in the editor, sorry!', 'amp' ) }

) } { ! url && ( - -

{ __( 'Add required data to use the block.' ) }

+ +

{ __( 'Add required data to use the block.', 'amp' ) }

) } diff --git a/blocks/amp-ima-video/index.js b/blocks/amp-ima-video/index.js index 6065cdc2304..093f5ad8a3e 100644 --- a/blocks/amp-ima-video/index.js +++ b/blocks/amp-ima-video/index.js @@ -19,12 +19,12 @@ const { export default registerBlockType( 'amp/amp-ima-video', { - title: __( 'AMP IMA Video' ), - description: __( 'Embeds a video player for instream video ads that are integrated with the IMA SDK' ), + title: __( 'AMP IMA Video', 'amp' ), + description: __( 'Embeds a video player for instream video ads that are integrated with the IMA SDK', 'amp' ), category: 'common', icon: 'embed-generic', keywords: [ - __( 'Embed' ) + __( 'Embed', 'amp' ) ], // @todo Perhaps later add subtitles option and additional source options? @@ -58,8 +58,8 @@ export default registerBlockType( edit( { attributes, isSelected, setAttributes } ) { const { dataDelayAdRequest, dataTag, dataSrc, dataPoster, layout, height, width } = attributes; const ampLayoutOptions = [ - { value: 'responsive', label: __( 'Responsive' ) }, - { value: 'fixed', label: __( 'Fixed' ) } + { value: 'responsive', label: __( 'Responsive', 'amp' ) }, + { value: 'fixed', label: __( 'Fixed', 'amp' ) } ]; let dataSet = false; @@ -71,42 +71,42 @@ export default registerBlockType( { isSelected && ( - + ( setAttributes( { dataTag: value } ) ) } /> ( setAttributes( { dataSrc: value } ) ) } /> ( setAttributes( { dataPoster: value } ) ) } /> ( setAttributes( { dataDelayAdRequest: ! dataDelayAdRequest } ) ) } /> ( setAttributes( { layout: value } ) ) } /> ( setAttributes( { width: value } ) ) } /> ( setAttributes( { height: value } ) ) } /> @@ -116,16 +116,16 @@ export default registerBlockType( } { dataSet && ( - +

{ dataSrc }

-

{ __( 'Previews for this are unavailable in the editor, sorry!' ) }

+

{ __( 'Previews for this are unavailable in the editor, sorry!', 'amp' ) }

) } { ! dataSet && ( - -

{ __( 'Add required data to use the block.' ) }

+ +

{ __( 'Add required data to use the block.', 'amp' ) }

) } diff --git a/blocks/amp-jwplayer/index.js b/blocks/amp-jwplayer/index.js index ea063ba517b..b764f928d21 100644 --- a/blocks/amp-jwplayer/index.js +++ b/blocks/amp-jwplayer/index.js @@ -18,12 +18,12 @@ const { export default registerBlockType( 'amp/amp-jwplayer', { - title: __( 'AMP JW Player' ), - description: __( 'Displays a cloud-hosted JW Player.' ), + title: __( 'AMP JW Player', 'amp' ), + description: __( 'Displays a cloud-hosted JW Player.', 'amp' ), category: 'common', icon: 'embed-generic', keywords: [ - __( 'Embed' ) + __( 'Embed', 'amp' ) ], attributes: { @@ -53,12 +53,12 @@ export default registerBlockType( edit( { attributes, isSelected, setAttributes } ) { const { dataPlayerId, dataMediaId, dataPlaylistId, layout, height, width } = attributes; const ampLayoutOptions = [ - { value: 'responsive', label: __( 'Responsive' ) }, - { value: 'fixed-height', label: __( 'Fixed height' ) }, - { value: 'fixed', label: __( 'Fixed' ) }, - { value: 'fill', label: __( 'Fill' ) }, - { value: 'flex-item', label: __( 'Flex-item' ) }, - { value: 'nodisplay', label: __( 'No Display' ) } + { value: 'responsive', label: __( 'Responsive', 'amp' ) }, + { value: 'fixed-height', label: __( 'Fixed height', 'amp' ) }, + { value: 'fixed', label: __( 'Fixed', 'amp' ) }, + { value: 'fill', label: __( 'Fill', 'amp' ) }, + { value: 'flex-item', label: __( 'Flex-item', 'amp' ) }, + { value: 'nodisplay', label: __( 'No Display', 'amp' ) } ]; let url = false; @@ -74,37 +74,37 @@ export default registerBlockType( { isSelected && ( - + ( setAttributes( { dataPlayerId: value } ) ) } /> ( setAttributes( { dataMediaId: value } ) ) } /> ( setAttributes( { dataPlaylistId: value } ) ) } /> ( setAttributes( { layout: value } ) ) } /> ( setAttributes( { width: value } ) ) } /> ( setAttributes( { height: value } ) ) } /> @@ -114,16 +114,16 @@ export default registerBlockType( } { url && ( - +

{ url }

-

{ __( 'Previews for this are unavailable in the editor, sorry!' ) }

+

{ __( 'Previews for this are unavailable in the editor, sorry!', 'amp' ) }

) } { ! url && ( - -

{ __( 'Add required data to use the block.' ) }

+ +

{ __( 'Add required data to use the block.', 'amp' ) }

) } diff --git a/blocks/amp-mathml/index.js b/blocks/amp-mathml/index.js index e8d39ca35c5..aadeba6ddc2 100644 --- a/blocks/amp-mathml/index.js +++ b/blocks/amp-mathml/index.js @@ -16,12 +16,12 @@ const { export default registerBlockType( 'amp/amp-mathml', { - title: __( 'AMP MathML' ), + title: __( 'AMP MathML', 'amp' ), category: 'common', icon: 'welcome-learn-more', keywords: [ - __( 'Mathematical formula' ), - __( 'Scientific content ' ) + __( 'Mathematical formula', 'amp' ), + __( 'Scientific content ', 'amp' ) ], attributes: { @@ -37,7 +37,7 @@ export default registerBlockType( setAttributes( { dataFormula: value } ) } /> ); diff --git a/blocks/amp-o2-player/index.js b/blocks/amp-o2-player/index.js index 82c21391adf..41a111d5538 100644 --- a/blocks/amp-o2-player/index.js +++ b/blocks/amp-o2-player/index.js @@ -19,12 +19,12 @@ const { export default registerBlockType( 'amp/amp-o2-player', { - title: __( 'AMP O2 Player' ), + title: __( 'AMP O2 Player', 'amp' ), category: 'common', icon: 'embed-generic', keywords: [ - __( 'Embed' ), - __( 'AOL O2Player' ) + __( 'Embed', 'amp' ), + __( 'AOL O2Player', 'amp' ) ], // @todo Add other useful macro toggles, e.g. showing relevant content. @@ -62,12 +62,12 @@ export default registerBlockType( edit( { attributes, isSelected, setAttributes } ) { const { autoPlay, dataPid, dataVid, dataBcid, dataBid, layout, height, width } = attributes; const ampLayoutOptions = [ - { value: 'responsive', label: __( 'Responsive' ) }, - { value: 'fixed-height', label: __( 'Fixed height' ) }, - { value: 'fixed', label: __( 'Fixed' ) }, - { value: 'fill', label: __( 'Fill' ) }, - { value: 'flex-item', label: __( 'Flex-item' ) }, - { value: 'nodisplay', label: __( 'No Display' ) } + { value: 'responsive', label: __( 'Responsive', 'amp' ) }, + { value: 'fixed-height', label: __( 'Fixed height', 'amp' ) }, + { value: 'fixed', label: __( 'Fixed', 'amp' ) }, + { value: 'fill', label: __( 'Fill', 'amp' ) }, + { value: 'flex-item', label: __( 'Flex-item', 'amp' ) }, + { value: 'nodisplay', label: __( 'No Display', 'amp' ) } ]; let url = false; @@ -79,47 +79,47 @@ export default registerBlockType( { isSelected && ( <InspectorControls key='inspector'> - <PanelBody title={ __( 'O2 Player Settings' ) }> + <PanelBody title={ __( 'O2 Player Settings', 'amp' ) }> <TextControl - label={ __( 'Player ID (required)' ) } + label={ __( 'Player ID (required)', 'amp' ) } value={ dataPid } onChange={ value => ( setAttributes( { dataPid: value } ) ) } /> <TextControl - label={ __( 'Buyer Company ID (either buyer or video ID is required)' ) } + label={ __( 'Buyer Company ID (either buyer or video ID is required)', 'amp' ) } value={ dataBcid } onChange={ value => ( setAttributes( { dataBcid: value } ) ) } /> <TextControl - label={ __( 'Video ID (either buyer or video ID is required)' ) } + label={ __( 'Video ID (either buyer or video ID is required)', 'amp' ) } value={ dataVid } onChange={ value => ( setAttributes( { dataVid: value } ) ) } /> <TextControl - label={ __( 'Playlist ID' ) } + label={ __( 'Playlist ID', 'amp' ) } value={ dataBid } onChange={ value => ( setAttributes( { dataBid: value } ) ) } /> <ToggleControl - label={ __( 'Autoplay' ) } + label={ __( 'Autoplay', 'amp' ) } checked={ autoPlay } onChange={ () => ( setAttributes( { autoPlay: ! autoPlay } ) ) } /> <SelectControl - label={ __( 'Layout' ) } + label={ __( 'Layout', 'amp' ) } value={ layout } options={ ampLayoutOptions } onChange={ value => ( setAttributes( { layout: value } ) ) } /> <TextControl type="number" - label={ __( 'Width (px)' ) } + label={ __( 'Width (px)', 'amp' ) } value={ width !== undefined ? width : '' } onChange={ value => ( setAttributes( { width: value } ) ) } /> <TextControl type="number" - label={ __( 'Height (px)' ) } + label={ __( 'Height (px)', 'amp' ) } value={ height } onChange={ value => ( setAttributes( { height: value } ) ) } /> @@ -129,16 +129,16 @@ export default registerBlockType( } { url && ( - <Placeholder label={ __( 'O2 Player' ) }> + <Placeholder label={ __( 'O2 Player', 'amp' ) }> <p className="components-placeholder__error">{ url }</p> - <p className="components-placeholder__error">{ __( 'Previews for this are unavailable in the editor, sorry!' ) }</p> + <p className="components-placeholder__error">{ __( 'Previews for this are unavailable in the editor, sorry!', 'amp' ) }</p> </Placeholder> ) } { ! url && ( - <Placeholder label={ __( 'O2 Player' ) }> - <p>{ __( 'Add required data to use the block.' ) }</p> + <Placeholder label={ __( 'O2 Player', 'amp' ) }> + <p>{ __( 'Add required data to use the block.', 'amp' ) }</p> </Placeholder> ) } diff --git a/blocks/amp-ooyala-player/index.js b/blocks/amp-ooyala-player/index.js index d261b2bc5c9..f4f396c6788 100644 --- a/blocks/amp-ooyala-player/index.js +++ b/blocks/amp-ooyala-player/index.js @@ -18,13 +18,13 @@ const { export default registerBlockType( 'amp/amp-ooyala-player', { - title: __( 'AMP Ooyala Player' ), - description: __( 'Displays an Ooyala video.' ), + title: __( 'AMP Ooyala Player', 'amp' ), + description: __( 'Displays an Ooyala video.', 'amp' ), category: 'common', icon: 'embed-generic', keywords: [ - __( 'Embed' ), - __( 'Ooyala video' ) + __( 'Embed', 'amp' ), + __( 'Ooyala video', 'amp' ) ], // @todo Add data-config attribute? @@ -59,10 +59,10 @@ export default registerBlockType( edit( { attributes, isSelected, setAttributes } ) { const { dataEmbedCode, dataPlayerId, dataPcode, dataPlayerVersion, layout, height, width } = attributes; const ampLayoutOptions = [ - { value: 'responsive', label: __( 'Responsive' ) }, - { value: 'fixed', label: __( 'Fixed' ) }, - { value: 'fill', label: __( 'Fill' ) }, - { value: 'flex-item', label: __( 'Flex-item' ) } + { value: 'responsive', label: __( 'Responsive', 'amp' ) }, + { value: 'fixed', label: __( 'Fixed', 'amp' ) }, + { value: 'fill', label: __( 'Fill', 'amp' ) }, + { value: 'flex-item', label: __( 'Flex-item', 'amp' ) } ]; let url = false; @@ -74,46 +74,46 @@ export default registerBlockType( { isSelected && ( <InspectorControls key='inspector'> - <PanelBody title={ __( 'Ooyala settings' ) }> + <PanelBody title={ __( 'Ooyala settings', 'amp' ) }> <TextControl - label={ __( 'Video embed code (required)' ) } + label={ __( 'Video embed code (required)', 'amp' ) } value={ dataEmbedCode } onChange={ value => ( setAttributes( { dataEmbedCode: value } ) ) } /> <TextControl - label={ __( 'Player ID (required)' ) } + label={ __( 'Player ID (required)', 'amp' ) } value={ dataPlayerId } onChange={ value => ( setAttributes( { dataPlayerId: value } ) ) } /> <TextControl - label={ __( 'Provider code for the account (required)' ) } + label={ __( 'Provider code for the account (required)', 'amp' ) } value={ dataPcode } onChange={ value => ( setAttributes( { dataPcode: value } ) ) } /> <SelectControl - label={ __( 'Player version' ) } + label={ __( 'Player version', 'amp' ) } value={ dataPlayerVersion } options={ [ - { value: 'v3', label: __( 'V3' ) }, - { value: 'v4', label: __( 'V4' ) } + { value: 'v3', label: __( 'V3', 'amp' ) }, + { value: 'v4', label: __( 'V4', 'amp' ) } ] } onChange={ value => ( setAttributes( { dataPlayerVersion: value } ) ) } /> <SelectControl - label={ __( 'Layout' ) } + label={ __( 'Layout', 'amp' ) } value={ layout } options={ ampLayoutOptions } onChange={ value => ( setAttributes( { layout: value } ) ) } /> <TextControl type="number" - label={ __( 'Width (px)' ) } + label={ __( 'Width (px)', 'amp' ) } value={ width !== undefined ? width : '' } onChange={ value => ( setAttributes( { width: value } ) ) } /> <TextControl type="number" - label={ __( 'Height (px)' ) } + label={ __( 'Height (px)', 'amp' ) } value={ height } onChange={ value => ( setAttributes( { height: value } ) ) } /> @@ -123,16 +123,16 @@ export default registerBlockType( } { url && ( - <Placeholder label={ __( 'Ooyala Player' ) }> + <Placeholder label={ __( 'Ooyala Player', 'amp' ) }> <p className="components-placeholder__error">{ url }</p> - <p className="components-placeholder__error">{ __( 'Previews for this are unavailable in the editor, sorry!' ) }</p> + <p className="components-placeholder__error">{ __( 'Previews for this are unavailable in the editor, sorry!', 'amp' ) }</p> </Placeholder> ) } { ! url && ( - <Placeholder label={ __( 'Ooyala Player' ) }> - <p>{ __( 'Add required data to use the block.' ) }</p> + <Placeholder label={ __( 'Ooyala Player', 'amp' ) }> + <p>{ __( 'Add required data to use the block.', 'amp' ) }</p> </Placeholder> ) } diff --git a/blocks/amp-reach-player/index.js b/blocks/amp-reach-player/index.js index 0c143be49e0..ff297598e87 100644 --- a/blocks/amp-reach-player/index.js +++ b/blocks/amp-reach-player/index.js @@ -18,13 +18,13 @@ const { export default registerBlockType( 'amp/amp-reach-player', { - title: __( 'AMP Reach Player' ), - description: __( 'Displays the Reach Player configured in the Beachfront Reach platform.' ), + title: __( 'AMP Reach Player', 'amp' ), + description: __( 'Displays the Reach Player configured in the Beachfront Reach platform.', 'amp' ), category: 'common', icon: 'embed-generic', keywords: [ - __( 'Embed' ), - __( 'Beachfront Reach video' ) + __( 'Embed', 'amp' ), + __( 'Beachfront Reach video', 'amp' ) ], attributes: { @@ -48,11 +48,11 @@ export default registerBlockType( edit( { attributes, isSelected, setAttributes } ) { const { dataEmbedId, layout, height, width } = attributes; const ampLayoutOptions = [ - { value: 'responsive', label: __( 'Responsive' ) }, - { value: 'fixed-height', label: __( 'Fixed Height' ) }, - { value: 'fixed', label: __( 'Fixed' ) }, - { value: 'fill', label: __( 'Fill' ) }, - { value: 'flex-item', label: __( 'Flex-item' ) } + { value: 'responsive', label: __( 'Responsive', 'amp' ) }, + { value: 'fixed-height', label: __( 'Fixed Height', 'amp' ) }, + { value: 'fixed', label: __( 'Fixed', 'amp' ) }, + { value: 'fill', label: __( 'Fill', 'amp' ) }, + { value: 'flex-item', label: __( 'Flex-item', 'amp' ) } ]; let url = false; @@ -64,27 +64,27 @@ export default registerBlockType( { isSelected && ( <InspectorControls key='inspector'> - <PanelBody title={ __( 'Reach settings' ) }> + <PanelBody title={ __( 'Reach settings', 'amp' ) }> <TextControl - label={ __( 'The Reach player embed id (required)' ) } + label={ __( 'The Reach player embed id (required)', 'amp' ) } value={ dataEmbedId } onChange={ value => ( setAttributes( { dataEmbedId: value } ) ) } /> <SelectControl - label={ __( 'Layout' ) } + label={ __( 'Layout', 'amp' ) } value={ layout } options={ ampLayoutOptions } onChange={ value => ( setAttributes( { layout: value } ) ) } /> <TextControl type="number" - label={ __( 'Width (px)' ) } + label={ __( 'Width (px)', 'amp' ) } value={ width !== undefined ? width : '' } onChange={ value => ( setAttributes( { width: value } ) ) } /> <TextControl type="number" - label={ __( 'Height (px)' ) } + label={ __( 'Height (px)', 'amp' ) } value={ height } onChange={ value => ( setAttributes( { height: value } ) ) } /> @@ -94,16 +94,16 @@ export default registerBlockType( } { url && ( - <Placeholder label={ __( 'Reach Player' ) }> + <Placeholder label={ __( 'Reach Player', 'amp' ) }> <p className="components-placeholder__error">{ url }</p> - <p className="components-placeholder__error">{ __( 'Previews for this are unavailable in the editor, sorry!' ) }</p> + <p className="components-placeholder__error">{ __( 'Previews for this are unavailable in the editor, sorry!', 'amp' ) }</p> </Placeholder> ) } { ! url && ( - <Placeholder label={ __( 'Reach Player' ) }> - <p>{ __( 'Add Reach player embed ID to use the block.' ) }</p> + <Placeholder label={ __( 'Reach Player', 'amp' ) }> + <p>{ __( 'Add Reach player embed ID to use the block.', 'amp' ) }</p> </Placeholder> ) } diff --git a/blocks/amp-springboard-player/index.js b/blocks/amp-springboard-player/index.js index 4a32ce35cf4..7f997096c46 100644 --- a/blocks/amp-springboard-player/index.js +++ b/blocks/amp-springboard-player/index.js @@ -18,12 +18,12 @@ const { export default registerBlockType( 'amp/amp-springboard-player', { - title: __( 'AMP Springboard Player' ), - description: __( 'Displays the Springboard Player used in the Springboard Video Platform' ), + title: __( 'AMP Springboard Player', 'amp' ), + description: __( 'Displays the Springboard Player used in the Springboard Video Platform', 'amp' ), category: 'common', icon: 'embed-generic', keywords: [ - __( 'Embed' ) + __( 'Embed', 'amp' ) ], attributes: { @@ -64,10 +64,10 @@ export default registerBlockType( edit( { attributes, isSelected, setAttributes } ) { const { dataSiteId, dataPlayerId, dataContentId, dataDomain, dataMode, dataItems, layout, height, width } = attributes; const ampLayoutOptions = [ - { value: 'responsive', label: __( 'Responsive' ) }, - { value: 'fixed', label: __( 'Fixed' ) }, - { value: 'fill', label: __( 'Fill' ) }, - { value: 'flex-item', label: __( 'Flex-item' ) } + { value: 'responsive', label: __( 'Responsive', 'amp' ) }, + { value: 'fixed', label: __( 'Fixed', 'amp' ) }, + { value: 'fill', label: __( 'Fill', 'amp' ) }, + { value: 'flex-item', label: __( 'Flex-item', 'amp' ) } ]; let url = false; @@ -79,57 +79,57 @@ export default registerBlockType( { isSelected && ( <InspectorControls key='inspector'> - <PanelBody title={ __( 'Springboard Player Settings' ) }> + <PanelBody title={ __( 'Springboard Player Settings', 'amp' ) }> <TextControl - label={ __( 'SprintBoard site ID (required)' ) } + label={ __( 'SprintBoard site ID (required)', 'amp' ) } value={ dataSiteId } onChange={ value => ( setAttributes( { dataSiteId: value } ) ) } /> <TextControl - label={ __( 'Player content ID (required)' ) } + label={ __( 'Player content ID (required)', 'amp' ) } value={ dataContentId } onChange={ value => ( setAttributes( { dataContentId: value } ) ) } /> <TextControl - label={ __( 'Player ID' ) } + label={ __( 'Player ID', 'amp' ) } value={ dataPlayerId } onChange={ value => ( setAttributes( { dataPlayerId: value } ) ) } /> <TextControl - label={ __( 'Springboard partner domain' ) } + label={ __( 'Springboard partner domain', 'amp' ) } value={ dataDomain } onChange={ value => ( setAttributes( { dataDomain: value } ) ) } /> <SelectControl - label={ __( 'Mode (required)' ) } + label={ __( 'Mode (required)', 'amp' ) } value={ dataMode } options={ [ - { value: 'video', label: __( 'Video' ) }, - { value: 'playlist', label: __( 'Playlist' ) } + { value: 'video', label: __( 'Video', 'amp' ) }, + { value: 'playlist', label: __( 'Playlist', 'amp' ) } ] } onChange={ value => ( setAttributes( { dataMode: value } ) ) } /> <TextControl type="number" - label={ __( 'Number of video is playlist (required)' ) } + label={ __( 'Number of video is playlist (required)', 'amp' ) } value={ dataItems } onChange={ value => ( setAttributes( { dataItems: value } ) ) } /> <SelectControl - label={ __( 'Layout' ) } + label={ __( 'Layout', 'amp' ) } value={ layout } options={ ampLayoutOptions } onChange={ value => ( setAttributes( { layout: value } ) ) } /> <TextControl type="number" - label={ __( 'Width (px)' ) } + label={ __( 'Width (px)', 'amp' ) } value={ width !== undefined ? width : '' } onChange={ value => ( setAttributes( { width: value } ) ) } /> <TextControl type="number" - label={ __( 'Height (px)' ) } + label={ __( 'Height (px)', 'amp' ) } value={ height } onChange={ value => ( setAttributes( { height: value } ) ) } /> @@ -139,16 +139,16 @@ export default registerBlockType( } { url && ( - <Placeholder label={ __( 'Springboard Player' ) }> + <Placeholder label={ __( 'Springboard Player', 'amp' ) }> <p className="components-placeholder__error">{ url }</p> - <p className="components-placeholder__error">{ __( 'Previews for this are unavailable in the editor, sorry!' ) }</p> + <p className="components-placeholder__error">{ __( 'Previews for this are unavailable in the editor, sorry!', 'amp' ) }</p> </Placeholder> ) } { ! url && ( - <Placeholder label={ __( 'Springboard Player' ) }> - <p>{ __( 'Add required data to use the block.' ) }</p> + <Placeholder label={ __( 'Springboard Player', 'amp' ) }> + <p>{ __( 'Add required data to use the block.', 'amp' ) }</p> </Placeholder> ) } diff --git a/contributing.md b/contributing.md index 9d505bf545a..e88ccf31dfa 100644 --- a/contributing.md +++ b/contributing.md @@ -31,7 +31,15 @@ npm install # (if you haven't done so yet) npm run build ``` -This will create an `amp.zip` in the plugin directory which you can install. The contents of this ZIP are also located in the `build` directory which you can `rsync` somewhere as well. +This will create an `amp.zip` in the plugin directory which you can install. The contents of this ZIP are also located in the `build` directory which you can `rsync` somewhere as well. + +TO create a build of the plugin as it will be deployed to WordPress.org, run: + +```bash +npm run build-release +``` + +Note that this will currently take much longer than a regular build because it generates the files required for translation. You also must have WP-CLI installed with the `i18n` package. ## Updating Allowed Tags And Attributes @@ -98,7 +106,7 @@ When you push a commit to your PR, Travis CI will run the PHPUnit tests and snif Contributors who want to make a new release, follow these steps: -1. Do `npm run build` and install the `amp.zip` onto a normal WordPress install running a stable release build; do smoke test to ensure it works. +1. Do `npm run build-release` and install the `amp.zip` onto a normal WordPress install running a stable release build; do smoke test to ensure it works. 2. Bump plugin versions in `package.json` (×1), `package-lock.json` (×1, just do `npm install` first), `composer.json` (×1), and in `amp.php` (×2: the metadata block in the header and also the `AMP__VERSION` constant). 3. Add changelog entry to readme. 4. Draft blog post about the new release. diff --git a/includes/admin/class-amp-editor-blocks.php b/includes/admin/class-amp-editor-blocks.php index 5dfa5bde558..63c8da18e01 100644 --- a/includes/admin/class-amp-editor-blocks.php +++ b/includes/admin/class-amp-editor-blocks.php @@ -129,7 +129,11 @@ public function enqueue_block_editor_assets() { true ); - wp_add_inline_script( 'amp-editor-blocks', sprintf( 'ampEditorBlocks.boot();' ) ); + wp_add_inline_script( + 'amp-editor-blocks', + 'wp.i18n.setLocaleData( ' . wp_json_encode( gutenberg_get_jed_locale_data( 'amp' ) ) . ', "amp" );' . sprintf( 'ampEditorBlocks.boot();' ), + 'before' + ); } /** diff --git a/languages/README.md b/languages/README.md new file mode 100644 index 00000000000..94e8f81da87 --- /dev/null +++ b/languages/README.md @@ -0,0 +1,10 @@ +Languages +========= + +The generated POT template file is not included in this repository. To create this file locally, run the following command: + +``` +npm run build +``` + +After the build completes, you'll find an `amp.pot` strings file in this directory. diff --git a/package-lock.json b/package-lock.json index 21c9a5167ad..093d0c2b235 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,28 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@wordpress/babel-plugin-makepot": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@wordpress/babel-plugin-makepot/-/babel-plugin-makepot-1.0.1.tgz", + "integrity": "sha512-n0ifXqE4jbEWxz+tCj3IM2nPH9sgelQx2ApKTPJNrOOMJq29s6RRXcUYzN8g68rNakXAGuFLlIRmPzIGrA1wWA==", + "dev": true, + "requires": { + "gettext-parser": "^1.3.1", + "lodash": "^4.17.5" + } + }, + "@wordpress/i18n": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@wordpress/i18n/-/i18n-1.1.1.tgz", + "integrity": "sha512-edJA7TEuBuMaUW39T1cK0GxjMqRdLNRsJgc0L1KDGnuo2ooIilasy4gvlm8VrkDTdKDs0I96tC4AfBoLS8fdXw==", + "dev": true, + "requires": { + "gettext-parser": "^1.3.1", + "jed": "^1.1.1", + "lodash": "^4.17.5", + "memize": "^1.0.5" + } + }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -3226,6 +3248,16 @@ "integrity": "sha1-BHpEl4n6Fg0Bj1SG7ZEyC27HiFw=", "dev": true }, + "gettext-parser": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/gettext-parser/-/gettext-parser-1.3.1.tgz", + "integrity": "sha512-W4t55eB/c7WrH0gbCHFiHuaEnJ1WiPJVnbFFiNEoh2QkOmuSLxs0PmJDGAmCQuTJCU740Fmb6D+2D/2xECWZGQ==", + "dev": true, + "requires": { + "encoding": "^0.1.12", + "safe-buffer": "^5.1.1" + } + }, "glob": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", @@ -4104,6 +4136,12 @@ "whatwg-fetch": ">=0.10.0" } }, + "jed": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/jed/-/jed-1.1.1.tgz", + "integrity": "sha1-elSbvZ/+FYWwzQoZHiAwVb7ldLQ=", + "dev": true + }, "js-tokens": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", @@ -4369,6 +4407,12 @@ "mimic-fn": "^1.0.0" } }, + "memize": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/memize/-/memize-1.0.5.tgz", + "integrity": "sha512-Dm8Jhb5kiC4+ynYsVR4QDXKt+o2dfqGuY4hE2x+XlXZkdndlT80bJxfcMv5QGp/FCy6MhG7f5ElpmKPFKOSEpg==", + "dev": true + }, "memoizee": { "version": "0.2.6", "resolved": "https://registry.npmjs.org/memoizee/-/memoizee-0.2.6.tgz", diff --git a/package.json b/package.json index 07950afc820..6eeab252afe 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,8 @@ "babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-plugin-transform-react-jsx": "^6.24.1", "babel-plugin-transform-runtime": "^6.23.0", + "@wordpress/babel-plugin-makepot": "^1.0.1", + "@wordpress/i18n": "^1.1.0", "babel-preset-env": "^1.7.0", "cross-env": "^5.1.5", "eslint": "^4.19.1", @@ -30,7 +32,9 @@ }, "main": "blocks/index.js", "scripts": { - "build": "cross-env BABEL_ENV=production webpack; grunt build", + "pot-to-php": "pot-to-php languages/amp-js.pot languages/amp-translations.php amp", + "build": "grunt build; grunt create-build-zip", + "build-release": "grunt build-release; grunt create-build-zip", "deploy": "grunt deploy", "dev": "cross-env BABEL_ENV=default webpack --watch" }