5
5
*/
6
6
import React from 'react' ;
7
7
import debug from 'debug' ;
8
- import request from 'superagent' ;
9
8
import { isEnabled } from 'config' ;
10
9
import { has , uniqueId } from 'lodash' ;
11
10
import { setLocaleData } from '@wordpress/i18n' ;
@@ -19,6 +18,8 @@ import { setAllSitesSelected } from 'state/ui/actions';
19
18
import { getSelectedSiteId , getSelectedSiteSlug } from 'state/ui/selectors' ;
20
19
import { EDITOR_START } from 'state/action-types' ;
21
20
import { initGutenberg } from './init' ;
21
+ import { getAtUrl } from 'state/data-getters' ;
22
+ import { waitForData } from 'state/data-layer/http-data' ;
22
23
23
24
function determinePostType ( context ) {
24
25
if ( context . path . startsWith ( '/gutenberg/post/' ) ) {
@@ -54,18 +55,20 @@ export const jetpackBlocki18n = ( context, next ) => {
54
55
return next ( ) ;
55
56
}
56
57
57
- const languageFileUrl =
58
- 'https://widgets.wp.com/languages/jetpack-gutenberg-blocks/' + localeSlug + '.json' ;
58
+ const languageFileUrl = `https://widgets.wp.com/languages/jetpack-gutenberg-blocks/${ localeSlug } .json` ;
59
59
60
- request . get ( languageFileUrl ) . end ( ( error , response ) => {
61
- if ( error ) {
60
+ waitForData ( {
61
+ translations : ( ) => getAtUrl ( languageFileUrl ) ,
62
+ } ) . then ( ( { translations : { state : requestState , data } } ) => {
63
+ if ( requestState === 'failure' ) {
62
64
debug (
63
- ' Encountered an error loading locale file for ' + localeSlug + ' . Falling back to English.'
65
+ ` Encountered an error loading locale file for ${ localeSlug } . Falling back to English.`
64
66
) ;
65
- return next ( ) ;
66
67
}
67
68
68
- setLocaleData ( response . body , 'jetpack' ) ;
69
+ if ( data ) {
70
+ setLocaleData ( data . body , 'jetpack' ) ;
71
+ }
69
72
70
73
next ( ) ;
71
74
} ) ;
0 commit comments