[wp-trac] [WordPress Trac] #20491: Introduce some JavaScript i18n functions

WordPress Trac noreply at wordpress.org
Fri Sep 23 20:50:31 UTC 2016


#20491: Introduce some JavaScript i18n functions
--------------------------------------+-----------------------------
 Reporter:  johnbillion               |       Owner:  swissspidy
     Type:  enhancement               |      Status:  assigned
 Priority:  normal                    |   Milestone:  Future Release
Component:  I18N                      |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  javascript
--------------------------------------+-----------------------------

Comment (by ocean90):

 Replying to [comment:42 swissspidy]:
 > In [attachment:20491.6.diff]:
 >
 > * Introduce `wp.i18n.loadLocaleData()` and `wp.i18n.getLocale()`.
 > * Introduce `get_js_i18n_data()` to load a JSON translation file.
 > * Introduce `WP_Scripts:: load_translation_file()` to pass that JSON to
 `wp.i18n.loadLocaleData()`.
 > * Add some more QUnit tests.
 >
 > If `get_js_i18n_data()` and `WP_Scripts:: load_translation_file()` seem
 legit I'll happily continue working on it.


 Nice.

 I think the naming can be improved. Maybe
 `WP_Scripts::add_json_localization()` or
 `WP_Scripts::localize_with_json()` for
 `WP_Scripts::load_translation_file()`?
 I'm not a fan of the loop in `get_js_i18n_data()`. `WP_LANG_DIR ` should
 only be checked if `$domain` is 'default'. Can we require that a path
 needs to be set: `get_js_i18n_data( $domain, $path )`? Or a `$context`
 which can be [core|theme|plugin]?

 I noticed that `escape()` still uses `_.keys()` which is an Underscore
 function.

 [[BR]]

 > Regarding `sprintf()`, this patch also removes `wp.i18n.sprintf` as
 Jed's implementation is really out of date. Jed even encourages removing
 it from its source code:

 +1, although it seems like Jed uses it at least once in line 147.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/20491#comment:45>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list