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

i18n: Add domain argument to localization functions #5167

Closed
aduth opened this issue Feb 20, 2018 · 3 comments · Fixed by #5235
Closed

i18n: Add domain argument to localization functions #5167

aduth opened this issue Feb 20, 2018 · 3 comments · Fixed by #5235
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time Internationalization (i18n) Issues or PRs related to internationalization efforts [Type] Task Issues or PRs that have been broken down into an individual action to take

Comments

@aduth
Copy link
Member

aduth commented Feb 20, 2018

Gutenberg was localized without explicit domain in its JavaScript gettext implementation with the following assumptions in mind:

  • It would make its way to core, where the default strings use the inferred empty domain
  • At worst, a domain could be "injected" as part of the string extraction step as a parameter to the extraction utility

Since these assumptions do not hold true for plugin code, and we should seek to open up localization tools more broadly, we should introduce a domain parameter to the localization functions.

As part of this, we may consider being explicit in specifying gutenberg domain for strings within Gutenberg, since we do this in PHP code and Gutenberg is still technically a plugin. That said, the plugin manifest does not specify the text domain.

This should not be a very difficult task, as it's merely a matter of adding the argument and using the domain-prefixed Jed functions. For example:

Before:

export function __( text ) {
	return getI18n().gettext( text );
}

(Reference)

After:

export function __( text, domain ) {
	return getI18n().dgettext( domain, text );
}

(Repeat for _x, _n, _nx)

@aduth aduth added Good First Issue An issue that's suitable for someone looking to contribute for the first time Internationalization (i18n) Issues or PRs related to internationalization efforts [Type] Task Issues or PRs that have been broken down into an individual action to take labels Feb 20, 2018
@Rahmon
Copy link
Contributor

Rahmon commented Feb 22, 2018

dgettext function has 'domain' parameter. So the correct should be "return getI18n().dgettext( domain, text );". Right?

@aduth
Copy link
Member Author

aduth commented Feb 23, 2018

Yes, silly oversight on my part. Thanks for the correction! I've updated the original text.

@ocean90
Copy link
Member

ocean90 commented Feb 24, 2018

That said, the plugin manifest does not specify the text domain.

You mean Text Domain and Domain Path? Both can be omitted if the plugin is in the plugin directory and requires at least WordPress 4.6. See https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#domain-path and https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#loading-text-domain.

@grappler grappler mentioned this issue Mar 26, 2018
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time Internationalization (i18n) Issues or PRs related to internationalization efforts [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants