-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 new APIs for React bindings #28784
Conversation
Size Change: +281 B (0%) Total Size: 1.37 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question, otherwise this looks good to me. Thanks for breaking it out 👍
packages/i18n/src/create-i18n.js
Outdated
* Regular expression that matches i18n hooks like `i18n.gettext`, `i18n.ngettext`, | ||
* `i18n.gettext_domain` or `i18n.ngettext_with_context` | ||
*/ | ||
const I18N_HOOK_REGEXP = /^i18n\.(n?)gettext(_|$)/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to match i18n.has_translation
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point 🙂 When I was adding this regexp and the code that uses it, the i18n.has_translation
filter didn't exist yet. The filter cannot change the result of __()
, but it can change result of hasTranslation()
which is one of the functions that the React bindings expose. I'll add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in a245ae0
Not sure I can really review as such, but this certainly doesn't break anything I'm doing. So 👍 from me. |
Spinoff from #28465 that adds several new APIs to
@wordpress/i18n
, with documentations and tests:defaultI18n
export that exports the defaultI18n
instance, in addition to already existing one-by-one method exportsgetLocaleData
to retrieve the internal Tannin structure. Counterpart to existingsetLocaleData
hasTranslation
to check if a given translation exists. Customizable with thehas_translation
filtersubscribe
to subscribe to updates whensetLocaleData
is called or hooks added or removed -- anything that makes a__( ... )
translation call return a different resultDetails were already discussed in #28465. Cc @leewillis77 for review.