Gutenberg: wp.i18n custom domain

Created on 22 Dec 2017  路  2Comments  路  Source: WordPress/gutenberg

Issue Overview

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

Append item into existing Jed instance

One 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.

Possible Solution


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

Related Issues and/or PRs

3955

Todos

  • [x] Think about a possible solution
  • [x] Come up with a PR which would allow us to specify the text domain for __() family of helpers
Internationalization (i18n)

Most helpful comment

Looks like this has been fixed in #5167/#5235

All 2 comments

Looks like this has been fixed in #5167/#5235

Awesome 馃帀 The next step would be to get the utility on NPM and we're done!

Was this page helpful?
0 / 5 - 0 ratings