[wp-trac] [WordPress Trac] #20491: Introduce some JavaScript i18n functions
WordPress Trac
noreply at wordpress.org
Fri Sep 23 16:21:27 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:43 jdgrimes]:
> I don't know if this has been mentioned, but in regard to `sprintf()`:
in JS that is already using Underscores anyway, it is possible to use
Underscores templates to do this. I have done this before.
>
> {{{#!php
> $text = sprintf( __( 'String with %s.' ), '{{placeholder}}' );
> }}}
>
> {{{#!js
> var text = wp.template( l10nTemplateFromPHP, value );
> }}}
>
> (Just a POC from off the top of my head.)
Interesting! Thanks for sharing. Loading 16KB of JS (the size of
underscore.min.js) for using `sprintf()` is not a viable solution for core
though. That's why I've opened #38147 to suggest adding the lightweight
sprintf.js library instead.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/20491#comment:44>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list