[wp-trac] [WordPress Trac] #45425: Add a filter to the translation file location for script localisation

WordPress Trac noreply at wordpress.org
Fri Dec 14 22:32:12 UTC 2018


#45425: Add a filter to the translation file location for script localisation
--------------------------+-------------------------
 Reporter:  johnbillion   |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  5.0.2
Component:  I18N          |     Version:  5.0
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  javascript
--------------------------+-------------------------

Comment (by dimadin):

 Replying to [comment:13 swissspidy]:
 > @dimadin Correct, because of plural forms we cannot do this on the PHP
 side. That's one of the reasons we have this new JS functionality in the
 first place.

 I did research. There are
 [https://www.wpdirectory.net/search/01CYPJQ96JZWR83YMJ11PGM9EP less than
 60 plugins] in WP.org repository that use `ngettext` filter. Even smaller
 number of those actually accept fourth parameter, number used for
 determining what plural form to use. Of those that accept it, not all use
 it. So basically many are filtering plural strings the same way they
 filter standard strings, without paying attention is that singular or
 plural form (they even use the same callback functions).

 I'm attaching function I made that is callback on proposed
 `load_script_translation` filter (from attachment:45425.diff) and that
 loops through all strings from JavaScript translations and applies
 `gettext` or `gettext_with_context` filter on them. If string has plural
 form, it applies `gettext`/`gettext_with_context` filter on each plural
 form. This will restore most uses of existing `gettext` filters, only
 those that really need number for plural strings will need JS
 implementation.

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


More information about the wp-trac mailing list