Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#50235 closed enhancement (fixed)

Use wp.i18n for translatable strings in wp-admin/js/updates.js

Reported by: ocean90's profile ocean90 Owned by: ocean90's profile ocean90
Milestone: 5.5 Priority: normal
Severity: normal Version:
Component: I18N Keywords: has-patch has-dev-note
Focuses: javascript Cc:

Description

JavaScript translation support is available since 5.0 (#45103) and so far only used in the block editor, site health, and media views. Other scripts are still using the old way via wp_localize_script().

Issues, that a switch to wp.i18n would solve:

  • The current way in script-loader.php (did_action( 'init' ) && $scripts->localize() initializes all the translations even if the script isn't used.
  • wp_localize_script() has no proper support for plural forms.
  • Since script-loader.php is in wp-includes the translations are all part of the front-end PO/MO files while some of them are only used in wp-admin.

Therefore I'm proposing to increase the usage of wp.i18n. The change should be processed file by file.

This ticket is for wp-admin/js/updates.js.

Change History (7)

This ticket was mentioned in PR #294 on WordPress/wordpress-develop by ocean90.


4 years ago
#1

  • Keywords has-patch added

#2 @ocean90
4 years ago

  • Owner set to ocean90
  • Resolution set to fixed
  • Status changed from new to closed

In 47884:

I18N: Use wp.i18n for translatable strings in wp-admin/js/updates.js.

This removes the usage of wp_localize_script() for passing translations to the script and instead adds the translatable strings in the script directly through the use of wp.i18n and its utilities.

Props swissspidy, ocean90.
See #20491.
Fixes #50235.

#3 follow-up: @aduth
4 years ago

Am I correct in thinking that the script registration should have been updated to include wp-i18n as a dependency of the updates script handle?

https://github.com/WordPress/wordpress-develop/blob/9bea5b34/src/wp-includes/script-loader.php#L1436

#4 in reply to: ↑ 3 @ocean90
4 years ago

Replying to aduth:

Am I correct in thinking that the script registration should have been updated to include wp-i18n as a dependency of the updates script handle?

WP_Scripts::set_translations() handles that for us.

#5 @ocean90
4 years ago

  • Summary changed from wp-admin/js/updates.js: Use wp.i18n for JavaScript translations to Use wp.i18n for translatable strings in wp-admin/js/updates.js

#6 @justinahinon
4 years ago

  • Keywords needs-dev-note added
Note: See TracTickets for help on using tickets.