Skip to content

Commit

Permalink
Bring i18n functionality up to date
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Jan 24, 2019
1 parent 0259f7b commit b692893
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 75 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,5 @@ module.exports = function( api ) {
},
],
],
env: {
production: {
plugins: [
[
'@wordpress/babel-plugin-makepot',
{
output: 'languages/gutenberg.pot',
},
],
],
},
},
};
};
4 changes: 0 additions & 4 deletions bin/build-plugin-zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 0 additions & 10 deletions languages/README.md

This file was deleted.

22 changes: 13 additions & 9 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}
}

/**
Expand Down Expand Up @@ -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' );
}

/**
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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' );
}
Expand Down
11 changes: 5 additions & 6 deletions lib/i18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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' );
32 changes: 0 additions & 32 deletions phpunit/class-i18n-functions-test.php

This file was deleted.

0 comments on commit b692893

Please sign in to comment.