[wp-hackers] _n javascript variant?

Stephen Harris contact at stephenharris.info
Wed Jul 16 15:51:40 UTC 2014


I had a similar problem recently when working in a Backbone.js-heavy 
project. If the number of translatable strings is low, then you could 
still use wp_localize_script() to load the plural translations as we all 
as singular. Obviously this isn't entirely ideal, as you don't know a 
priori how many different plural forms there are (though this list is 
pretty extensive 
http://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html).

For a variety of reasons I went down a different route of generating a 
.json version of the .po file, and then used that data client-side with 
few simple functions to look-up translations. You essentially just use 
wp_localize_script() with the appropriate .json data. I use a Grunt task 
to generate the .json files, so I don't need to worry about things 
falling out of sync. This still has some drawbacks, not least because my 
implementation only handles one plural form (I plan to improve on this). 
Additionally, it lives out of the scope of "language packs" which .org 
hosted plug-ins can take advantage of. Nevertheless, details of this 
approach can be found here: 
http://stephenharris.info/grunt-wordpress-development-iv-another-task-for-internationalisation/.

Stephen




More information about the wp-hackers mailing list