-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Try/localize url no calypso #47358
Try/localize url no calypso #47358
Conversation
- Restores old i18n-utils lib tests - Removes calypso dep from i18n-utils - Makes locale requried param - Updates up tests, removes mocks
Caution: This PR affects files in the Editing Toolkit Plugin on WordPress.com D52650-code has been created so you can easily test it on your sandbox. See this FieldGuide page about developing the Editing Toolkit Plugin for more info: PCYsg-ly5-p2 |
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: App Entrypoints (~472 bytes added 📈 [gzipped])
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Async-loaded Components (~131 bytes added 📈 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
const { i18nLocale } = useI18n(); | ||
|
||
return { | ||
locale: i18nLocale, | ||
localizeUrl: ( fullUrl: string, locale?: Locale ) => { | ||
if ( locale ) { | ||
return localizeUrl( fullUrl, locale ); |
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.
At first I didn't think we needed to support this case i.e. passing in their own value for locale
. If they had the locale all along then maybe we should have encouraged them to use the non-hook version.
But I think this is good actually. By virtue of the fact that useI18nUtils()
calls useI18n()
, it means the hook will re-render when the underlying locale data changes and that makes sense.
So what I'm saying is leave it like this 😅
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.
I don't know why GitHub is highlighting the locale: i18nLocale
line. I'm talking about the return localizeUrl( fullUrl, locale );
line.
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.
That's a nice side effect, the reason I did this was to maintain the same api publicly as the original version, but if you pull in the function directly you should be under no assumption that the locale is optional in that context - hopefully typescript catches this as an error?
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.
It's highlighting because I removed the locale in a later commit, I think I might have linked you the latest version to avoid seeing all your earlier (not yet merged) changes in the PR
Haven't tested this for the etk side yet, the approach worked for domain-picker
Changes proposed in this Pull Request
Testing instructions
Fixes #