-
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
Make gettext functions filterable #12517
Conversation
Ugh. Travis CI says |
Personally, I don't find this to be a pressing enhancement to consider, and while normally I'd not have such reservations, the translate functions are very hot paths. Alternatively, we could consider optimizing for the assumption that a filter will not be present in the majority of usage, and use a monkey-patching technique in overriding the translation functions when a filter is applied (see #8602 (comment)). |
Yeah it's definitely not a pressing enhancement, but sure something that will come up when JS I18N is getting more traction now with 5.0 and beyond. Parity and flexibility for devs is definitely important to some degree, IMO. Your monkey-patching idea sounds interesting, but I guess we would need to check first whether it would be worth the effort. I was thinking about doing some benchmarks or something, but I wouldn't know where to start there. |
For the record, we discussed some use cases at WCUS, mainly #12407 and https://core.trac.wordpress.org/ticket/45425#comment:10. It's certainly not ideal that the user experience for certain locales got worse. As for the technique used here, we could do some benchmarks to see whether monkey-patching should be explored or not. Although that could also be done in a later version. |
* @param {string} text Text to translate. | ||
* @param {string} domain Text domain. Unique identifier for retrieving translated strings. | ||
*/ | ||
return applyFilters( 'i18n.gettext', translation, text, domain ); |
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.
@aduth - we probably should also optimize applyFilters
to return early when there are no hooks to process. See:
It makes me think that having to run filters on every re-render might be bad for the performance of the application.
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.
Okey, I see #12517 (comment) which aligns with my comment.
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.
Yeah, it's not too horrible though. Outside of some conditions and a one-time setup, it amounts to incrementing the runs
each time it's called.
It looks like this is something that we need to decide about whether we continue working on this PR or we close it and keep it as a future reference when we decide it becomes necessary. |
Which weekly meeting are you referring to? I can have it included it in the agenda of tomorrow's JavaScript chat if you'd like. |
Yeah that could work. |
Recap from aforementioned meeting: https://make.wordpress.org/core/2019/04/10/javascript-chat-summary-april-9th-2019/ |
Description
Fixes #12516 by applying filters to all the gettext function in the i18n package.
How has this been tested?
Manually added some filters to these hooks.
Types of changes
New feature (non-breaking change which adds functionality): added new filters.
Checklist: