Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp.i18n custom domain #4147

Closed
2 tasks done
andreiglingeanu opened this issue Dec 22, 2017 · 2 comments
Closed
2 tasks done

wp.i18n custom domain #4147

andreiglingeanu opened this issue Dec 22, 2017 · 2 comments
Labels
Internationalization (i18n) Issues or PRs related to internationalization efforts

Comments

@andreiglingeanu
Copy link
Contributor

andreiglingeanu commented Dec 22, 2017

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? andreiglingeanu@feb0397

Related Issues and/or PRs

#3955

Todos

  • Think about a possible solution
  • Come up with a PR which would allow us to specify the text domain for __() family of helpers
@grappler
Copy link
Member

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

@ocean90 ocean90 closed this as completed Mar 26, 2018
@andreiglingeanu
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internationalization (i18n) Issues or PRs related to internationalization efforts
Projects
None yet
Development

No branches or pull requests

4 participants