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

WordPress Trac noreply at wordpress.org
Sat Sep 24 12:26:11 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 swissspidy):

 Replying to [comment:45 ocean90]:
 >
 > 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 had a hard time thinking of a good name, so +1. I'll move forward with
 `WP_Scripts::add_json_localization()` for the time being, unless we come
 up with something better.

 > 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]?

 `$context` sounds interesting. The alternative is to make it more like
 `load_*_textdomain()` with a different function per context.

 Idea that came to mind right now: Assuming the MO files are already
 loaded, we could probably get the path to the MO file from `$l10n[ $domain
 ]` and derive the JSON file from there.

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

 Good catch. I thought I had removed all underscore leftovers in the latest
 patch. Will fix in the next one.

 > > 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.

 Yeah I saw that too, although that line looks irrelevant for our use case.
 See https://github.com/SlexAxton/Jed/pull/46 and
 https://github.com/SlexAxton/Jed/pull/47 for more information about how
 Jed's version of `sprintf()` is different. Keeping the `sprintf()` part
 would make it easier to maintain.

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


More information about the wp-trac mailing list