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

WordPress Trac noreply at wordpress.org
Tue Feb 21 09:57:26 UTC 2017


#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, rest-api
--------------------------------------+-----------------------------------

Comment (by swissspidy):

 > One benefit of the current implementation is to make things easier for
 developers, more maintainable, and to make string extraction easier.

 I've been looking into Drupal recently and they expose the same `t()` and
 `formatPlural()`functions from PHP in JavaScript. See
 https://www.drupal.org/docs/8/api/translation-api/overview. Example:
 `Drupal.t('May', {}, {context: "Long month name"});` (the second argument
 is for placeholders to replace).

 > This includes extracting translator comments, which I don't think i18n-
 calypso supports at the moment.

 Never mind, it's supported. See https://github.com/Automattic/i18n-
 calypso#options. Example:

 {{{
 var content = i18n.translate( 'g:i:s a', {
         comment: 'draft saved date format, see http://php.net/date'
     } );
 }}}


 ---

 I agree that it's best to parse the JavaScript using JavaScript.

 Regarding the translation function, I can see the benefits of both a JS
 implementation of `__()`et al, as well as having "one function to rule
 them all". The only difference is basically translator comments support,
 so we could theoretically implement both if `/* translators: */` parsing
 is easily possible.

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


More information about the wp-trac mailing list