The problem is this one: We want to be able to use wp.i18n lib in JS from third-party themes/plugins. There are almost no problem that would stop us from doing so, besides a couple of small inconveniences
Jed instanceOne thing that's currently almost impossible is to add existing translations into the global wp.i18n instance. Of course one could go about:
wp.i18n.setLocaleData({
...wp.i18n.getI18n().options,
locale_data: {
gutenberg: {
...wp.i18n.getI18n().options.locale_data.gutenberg,
['Gutenberg Team']: ['Echipa Gutenberg'],
},
},
})
This solution is not viable because we have to re-use gutenberg domain and that's the biggest issue. Also, there's no way to swap out the current domain with the global wp.i18n.__() helper, just like we do on the PHP side __('Text', 'custom-domain').
Without these points being addressed there's no reason to even think about publishing this library to NPM. It just won't be usable outside of the Gutenberg scope.
One way to deal with that would be to allow the domain as the second argument of the __() family of helpers. You could always do const __ = (text, domain = 'gutenberg') => {...} internally, to keep backward compatibility with your own code.
Thanks for considering that!
BTW, I have tried a couple of things locally and come up with some simple tests for wp.i18n. Would you be interested in getting a PR which would contain them? https://github.com/andreiglingeanu/gutenberg/commit/feb0397b504231f1fd1cbc4500ba28200fa49b96
__() family of helpersLooks like this has been fixed in #5167/#5235
Awesome 馃帀 The next step would be to get the utility on NPM and we're done!
Most helpful comment
Looks like this has been fixed in #5167/#5235