Skip to content

Commit

Permalink
[RNMobile][Embed block] Add device's locale to preview content (#33858)
Browse files Browse the repository at this point in the history
* Add locale to block editor settings

* Add localized embed content

* Sort sandbox props

* Update react-native-editor changelog
  • Loading branch information
fluiddot committed Sep 9, 2021
1 parent eb1071f commit 7c88877
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
9 changes: 7 additions & 2 deletions packages/block-library/src/embed/embed-preview.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import classnames from 'classnames/dedupe';
* WordPress dependencies
*/
import { View } from '@wordpress/primitives';

import { BlockCaption } from '@wordpress/block-editor';
import {
BlockCaption,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { __, sprintf } from '@wordpress/i18n';
import { memo, useState } from '@wordpress/element';
import { SandBox } from '@wordpress/components';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -38,6 +41,7 @@ const EmbedPreview = ( {
url,
} ) => {
const [ isCaptionSelected, setIsCaptionSelected ] = useState( false );
const { locale } = useSelect( blockEditorStore ).getSettings();

const wrapperStyle = styles[ 'embed-preview__wrapper' ];
const wrapperAlignStyle =
Expand Down Expand Up @@ -105,6 +109,7 @@ const EmbedPreview = ( {
>
<PreviewContent
html={ html }
lang={ locale }
title={ iframeTitle }
type={ sandboxClassnames }
providerUrl={ providerUrl }
Expand Down
6 changes: 2 additions & 4 deletions packages/components/src/sandbox/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ const EMPTY_ARRAY = [];

function Sandbox( {
containerStyle,
html = '',
customJS,
html = '',
lang = 'en',
providerUrl = '',
scripts = EMPTY_ARRAY,
styles = EMPTY_ARRAY,
Expand Down Expand Up @@ -185,9 +186,6 @@ function Sandbox( {
} );

function getHtmlDoc() {
// TODO: Use the device's locale
const lang = 'en';

// Put the html snippet into a html document, and update the state to refresh the WebView,
// we can use this in the future to inject custom styles or scripts.
// Scripts go into the body rather than the head, to support embedded content such as Instagram
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/components/provider/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class NativeEditorProvider extends Component {
componentDidMount() {
const {
capabilities,
locale,
updateSettings,
galleryWithImageBlocks,
} = this.props;
Expand All @@ -100,6 +101,7 @@ class NativeEditorProvider extends Component {
...capabilities,
...{ __unstableGalleryWithImageBlocks: galleryWithImageBlocks },
...this.getThemeColors( this.props ),
locale,
} );

this.subscriptionParentGetHtml = subscribeParentGetHtml( () => {
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ For each user feature we should also add a importance categorization label to i
## Unreleased
- [**] [Embed block] Implement WP embed preview component [#34004]
- [*] [Embed block] Fix content disappearing on Android when switching light/dark mode [#34207]
- [*] Embed block: Add device's locale to preview content [#33858]

## 1.61.0
- [**] Enable embed preview for a list of providers (for now only YouTube and Twitter) [#34446]
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native-editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const setupInitHooks = () => {
rawStyles,
rawFeatures,
galleryWithImageBlocks,
locale,
} = props;

if ( initialData === undefined && __DEV__ ) {
Expand Down Expand Up @@ -112,6 +113,7 @@ const setupInitHooks = () => {
rawStyles,
rawFeatures,
galleryWithImageBlocks,
locale,
};
}
);
Expand Down

0 comments on commit 7c88877

Please sign in to comment.