From b692893934fe50432cac8bd29064759f47d593bd Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 23 Jan 2019 20:43:47 -0500 Subject: [PATCH] Bring i18n functionality up to date --- .gitignore | 2 -- babel.config.js | 12 ------- bin/build-plugin-zip.sh | 4 --- .../backward-compatibility/deprecations.md | 3 ++ languages/README.md | 10 ------ lib/client-assets.php | 22 +++++++------ lib/i18n.php | 11 +++---- phpunit/class-i18n-functions-test.php | 32 ------------------- 8 files changed, 21 insertions(+), 75 deletions(-) delete mode 100644 languages/README.md delete mode 100644 phpunit/class-i18n-functions-test.php diff --git a/.gitignore b/.gitignore index 5ba04948b2faf7..2fb814f9616e02 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,6 @@ build-module build-style node_modules gutenberg.zip -languages/gutenberg.pot -/languages/gutenberg-translations.php # Directories/files that may appear in your environment .DS_Store diff --git a/babel.config.js b/babel.config.js index 6a903eff6c1d94..64997f2328e077 100644 --- a/babel.config.js +++ b/babel.config.js @@ -13,17 +13,5 @@ module.exports = function( api ) { }, ], ], - env: { - production: { - plugins: [ - [ - '@wordpress/babel-plugin-makepot', - { - output: 'languages/gutenberg.pot', - }, - ], - ], - }, - }, }; }; diff --git a/bin/build-plugin-zip.sh b/bin/build-plugin-zip.sh index a95f2ef74b23d5..1a6344fa2e67a7 100755 --- a/bin/build-plugin-zip.sh +++ b/bin/build-plugin-zip.sh @@ -97,8 +97,6 @@ status "Installing dependencies... 📦" npm install status "Generating build... 👷‍♀️" npm run build -status "Generating PHP file for wordpress.org to parse translations... 👷‍♂️" -npx pot-to-php ./languages/gutenberg.pot ./languages/gutenberg-translations.php gutenberg # Temporarily modify `gutenberg.php` with production constants defined. Use a # temp file because `bin/generate-gutenberg-php.php` reads from `gutenberg.php` @@ -118,8 +116,6 @@ zip -r gutenberg.zip \ post-content.php \ $vendor_scripts \ $build_files \ - languages/gutenberg.pot \ - languages/gutenberg-translations.php \ README.md # Reset `gutenberg.php`. diff --git a/docs/designers-developers/developers/backward-compatibility/deprecations.md b/docs/designers-developers/developers/backward-compatibility/deprecations.md index 85e82f25549c67..dcc2acadb2d7e8 100644 --- a/docs/designers-developers/developers/backward-compatibility/deprecations.md +++ b/docs/designers-developers/developers/backward-compatibility/deprecations.md @@ -21,6 +21,9 @@ The Gutenberg project's deprecation policy is intended to support backward compa - The PHP function `gutenberg_register_post_prepare_functions` has been removed. - The PHP function `gutenberg_silence_rest_errors` has been removed. - The PHP function `gutenberg_filter_post_type_labels` has been removed. +- The PHP function `gutenberg_load_plugin_textdomain` has been removed. +- The PHP function `gutenberg_get_jed_locale_data` has been removed. +- The PHP function `gutenberg_load_locale_data` has been removed. ## 4.5.0 - `Dropdown.refresh()` has been deprecated as the contained `Popover` is now automatically refreshed. diff --git a/languages/README.md b/languages/README.md deleted file mode 100644 index 3f3ba1d4478c68..00000000000000 --- a/languages/README.md +++ /dev/null @@ -1,10 +0,0 @@ -Languages -========= - -The generated POT template file is not included in this repository. To create this file locally, follow instructions from [CONTRIBUTING.md](https://github.com/WordPress/gutenberg/blob/master/CONTRIBUTING.md) to install the project, then run the following command: - -``` -npm run build -``` - -After the build completes, you'll find a `gutenberg.pot` strings file in this directory. diff --git a/lib/client-assets.php b/lib/client-assets.php index 630a50434c72fa..68c10a1fda422a 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -111,6 +111,16 @@ function register_tinymce_scripts() { function gutenberg_override_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { wp_deregister_script( $handle ); wp_register_script( $handle, $src, $deps, $ver, $in_footer ); + + // `WP_Dependencies::set_translations` will fall over on itself if setting + // translations on the `wp-i18n` handle, since it internally adds `wp-i18n` + // as a dependency of itself, exhausting memory. The same applies for the + // polyfill script, which is a dependency _of_ `wp-i18n`. + // + // See: https://core.trac.wordpress.org/ticket/46089 + if ( 'wp-i18n' !== $handle && 'wp-polyfill' !== $handle ) { + wp_set_script_translations( $handle, 'gutenberg' ); + } } /** @@ -963,14 +973,11 @@ function gutenberg_get_block_categories( $post ) { /** * Loads Gutenberg Locale Data. + * + * @deprecated 5.0.0 */ function gutenberg_load_locale_data() { - // Prepare Jed locale data. - $locale_data = gutenberg_get_jed_locale_data( 'gutenberg' ); - wp_add_inline_script( - 'wp-i18n', - 'wp.i18n.setLocaleData( ' . json_encode( $locale_data ) . ' );' - ); + _deprecated_function( __FUNCTION__, '5.0.0' ); } /** @@ -1151,8 +1158,6 @@ function gutenberg_editor_scripts_and_styles( $hook ) { $initial_edits = null; } - gutenberg_load_locale_data(); - // Preload server-registered block schemas. wp_add_inline_script( 'wp-blocks', @@ -1414,7 +1419,6 @@ function gutenberg_editor_scripts_and_styles( $hook ) { function gutenberg_load_list_reusable_blocks( $hook ) { $is_reusable_blocks_list_page = 'edit.php' === $hook && isset( $_GET['post_type'] ) && 'wp_block' === $_GET['post_type']; if ( $is_reusable_blocks_list_page ) { - gutenberg_load_locale_data(); wp_enqueue_script( 'wp-list-reusable-blocks' ); wp_enqueue_style( 'wp-list-reusable-blocks' ); } diff --git a/lib/i18n.php b/lib/i18n.php index ab347c8334285b..f9eaa94af65882 100644 --- a/lib/i18n.php +++ b/lib/i18n.php @@ -13,12 +13,15 @@ * Returns Jed-formatted localization data. * * @since 0.1.0 + * @deprecated 5.0.0 * * @param string $domain Translation domain. * * @return array */ function gutenberg_get_jed_locale_data( $domain ) { + _deprecated_function( __FUNCTION__, '5.0.0' ); + $translations = get_translations_for_domain( $domain ); $locale = array( @@ -43,12 +46,8 @@ function gutenberg_get_jed_locale_data( $domain ) { * Load plugin text domain for translations. * * @since 0.1.0 + * @deprecated 5.0.0 */ function gutenberg_load_plugin_textdomain() { - load_plugin_textdomain( - 'gutenberg', - false, - plugin_basename( gutenberg_dir_path() ) . '/languages/' - ); + _deprecated_function( __FUNCTION__, '5.0.0' ); } -add_action( 'plugins_loaded', 'gutenberg_load_plugin_textdomain' ); diff --git a/phpunit/class-i18n-functions-test.php b/phpunit/class-i18n-functions-test.php deleted file mode 100644 index db8abe35bb7a77..00000000000000 --- a/phpunit/class-i18n-functions-test.php +++ /dev/null @@ -1,32 +0,0 @@ -markTestSkipped( 'The path is not matching in docker test environment. Needs further investigation.' ); - return; - } - - add_action( 'load_textdomain', array( $this, 'check_arguments_in_load_textdomaincheck' ), 10, 2 ); - gutenberg_load_plugin_textdomain(); - } - - public function check_arguments_in_load_textdomaincheck( $domain, $mofile ) { - $content_language_file_pattern = 'languages[\\/]plugins[\\/]gutenberg-[a-z]{2}_[A-Z]{2}.mo$'; - $plugin_language_file_pattern = 'gutenberg[\\/]languages[\\/]gutenberg-[a-z]{2}_[A-Z]{2}.mo$'; - $regex_pattern = '#' . $content_language_file_pattern . '|' . $plugin_language_file_pattern . '#'; - - $this->assertEquals( 'gutenberg', $domain ); - $this->assertRegExp( $regex_pattern, $mofile ); - } -}