From 066d8390989c40fe2f6e8fd79adc4c1546a28165 Mon Sep 17 00:00:00 2001 From: Cameron Voell Date: Tue, 7 Jul 2020 09:36:41 -0700 Subject: [PATCH] [RNmobile] Fix untranslated text (#23735) * Fix translations for media options * Load block-library lazily after translations occur to fix names of blocks in inserter. * lint fixes --- .../components/media-upload/index.native.js | 80 +++++++++---------- packages/edit-post/src/index.native.js | 9 +-- packages/react-native-editor/src/index.js | 11 +++ 3 files changed, 54 insertions(+), 46 deletions(-) diff --git a/packages/block-editor/src/components/media-upload/index.native.js b/packages/block-editor/src/components/media-upload/index.native.js index 655dbdcfaa35e..06bd6f6888b31 100644 --- a/packages/block-editor/src/components/media-upload/index.native.js +++ b/packages/block-editor/src/components/media-upload/index.native.js @@ -22,46 +22,6 @@ export const OPTION_TAKE_VIDEO = __( 'Take a Video' ); export const OPTION_TAKE_PHOTO = __( 'Take a Photo' ); export const OPTION_TAKE_PHOTO_OR_VIDEO = __( 'Take a Photo or Video' ); -const cameraImageSource = { - id: mediaSources.deviceCamera, // ID is the value sent to native - value: mediaSources.deviceCamera + '-IMAGE', // This is needed to diferenciate image-camera from video-camera sources. - label: __( 'Take a Photo' ), - types: [ MEDIA_TYPE_IMAGE ], - icon: capturePhoto, -}; - -const cameraVideoSource = { - id: mediaSources.deviceCamera, - value: mediaSources.deviceCamera, - label: __( 'Take a Video' ), - types: [ MEDIA_TYPE_VIDEO ], - icon: captureVideo, -}; - -const deviceLibrarySource = { - id: mediaSources.deviceLibrary, - value: mediaSources.deviceLibrary, - label: __( 'Choose from device' ), - types: [ MEDIA_TYPE_IMAGE, MEDIA_TYPE_VIDEO ], - icon: image, -}; - -const siteLibrarySource = { - id: mediaSources.siteMediaLibrary, - value: mediaSources.siteMediaLibrary, - label: __( 'WordPress Media Library' ), - types: [ MEDIA_TYPE_IMAGE, MEDIA_TYPE_VIDEO ], - icon: wordpress, - mediaLibrary: true, -}; - -const internalSources = [ - deviceLibrarySource, - cameraImageSource, - cameraVideoSource, - siteLibrarySource, -]; - export class MediaUpload extends React.Component { constructor( props ) { super( props ); @@ -92,6 +52,46 @@ export class MediaUpload extends React.Component { } getAllSources() { + const cameraImageSource = { + id: mediaSources.deviceCamera, // ID is the value sent to native + value: mediaSources.deviceCamera + '-IMAGE', // This is needed to diferenciate image-camera from video-camera sources. + label: __( 'Take a Photo' ), + types: [ MEDIA_TYPE_IMAGE ], + icon: capturePhoto, + }; + + const cameraVideoSource = { + id: mediaSources.deviceCamera, + value: mediaSources.deviceCamera, + label: __( 'Take a Video' ), + types: [ MEDIA_TYPE_VIDEO ], + icon: captureVideo, + }; + + const deviceLibrarySource = { + id: mediaSources.deviceLibrary, + value: mediaSources.deviceLibrary, + label: __( 'Choose from device' ), + types: [ MEDIA_TYPE_IMAGE, MEDIA_TYPE_VIDEO ], + icon: image, + }; + + const siteLibrarySource = { + id: mediaSources.siteMediaLibrary, + value: mediaSources.siteMediaLibrary, + label: __( 'WordPress Media Library' ), + types: [ MEDIA_TYPE_IMAGE, MEDIA_TYPE_VIDEO ], + icon: wordpress, + mediaLibrary: true, + }; + + const internalSources = [ + deviceLibrarySource, + cameraImageSource, + cameraVideoSource, + siteLibrarySource, + ]; + return internalSources.concat( this.state.otherMediaOptions ); } diff --git a/packages/edit-post/src/index.native.js b/packages/edit-post/src/index.native.js index 8ce7414637629..8aa2057b6c32e 100644 --- a/packages/edit-post/src/index.native.js +++ b/packages/edit-post/src/index.native.js @@ -5,7 +5,6 @@ import '@wordpress/core-data'; import '@wordpress/block-editor'; import '@wordpress/viewport'; import '@wordpress/notices'; -import { registerCoreBlocks } from '@wordpress/block-library'; import '@wordpress/format-library'; import { render } from '@wordpress/element'; @@ -15,7 +14,7 @@ import { render } from '@wordpress/element'; import './store'; import Editor from './editor'; -let blocksRegistered = false; +let editorInitialized = false; /** * Initializes the Editor and returns a componentProvider @@ -26,13 +25,11 @@ let blocksRegistered = false; * @param {Object} postId ID of the post to edit (unused right now) */ export function initializeEditor( id, postType, postId ) { - if ( blocksRegistered ) { + if ( editorInitialized ) { return; } - // register and setup blocks - registerCoreBlocks(); - blocksRegistered = true; + editorInitialized = true; render( , id ); } diff --git a/packages/react-native-editor/src/index.js b/packages/react-native-editor/src/index.js index bf2369b4a9d41..f8458c37c4704 100644 --- a/packages/react-native-editor/src/index.js +++ b/packages/react-native-editor/src/index.js @@ -82,6 +82,8 @@ const setupInitHooks = () => { ); }; +let blocksRegistered = false; + const setupLocale = ( locale, extraTranslations ) => { const setLocaleData = require( '@wordpress/i18n' ).setLocaleData; @@ -104,6 +106,15 @@ const setupLocale = ( locale, extraTranslations ) => { if ( gutenbergTranslations || extraTranslations ) { setLocaleData( translations ); } + + if ( blocksRegistered ) { + return; + } + + const registerCoreBlocks = require( '@wordpress/block-library' ) + .registerCoreBlocks; + registerCoreBlocks(); + blocksRegistered = true; }; reactNativeSetup();