Skip to content

Commit

Permalink
[RNmobile] Fix untranslated text (#23735)
Browse files Browse the repository at this point in the history
* Fix translations for media options

* Load block-library lazily after translations occur to fix names of blocks in inserter.

* lint fixes
  • Loading branch information
cameronvoell authored Jul 7, 2020
1 parent 297cb13 commit 066d839
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 46 deletions.
80 changes: 40 additions & 40 deletions packages/block-editor/src/components/media-upload/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}

Expand Down
9 changes: 3 additions & 6 deletions packages/edit-post/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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
Expand All @@ -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( <Editor postId={ postId } postType={ postType } />, id );
}
11 changes: 11 additions & 0 deletions packages/react-native-editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ const setupInitHooks = () => {
);
};

let blocksRegistered = false;

const setupLocale = ( locale, extraTranslations ) => {
const setLocaleData = require( '@wordpress/i18n' ).setLocaleData;

Expand All @@ -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();
Expand Down

0 comments on commit 066d839

Please sign in to comment.