Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#50235 closed enhancement (fixed)

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

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

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.


6 years ago
#1

  • Keywords has-patch added

#2 @ocean90
6 years ago

  • Owner set to ocean90
  • Resolution → fixed
  • Status new → 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
6 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
6 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
6 years ago

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

#6 @justinahinon
6 years ago

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