-
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
Framework: Add localization helpers to global wpcom instance #3348
Conversation
* Given a WPCOM parameter set, modifies the query such that a non-default | ||
* locale is added to the query parameter. | ||
* | ||
* @param {Object} params Original parameters |
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.
add -
?. I've gotten this suggestion before from @rralian
/**
* @param {Object} params - Original parameters
*/
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.
The hyphen itself is optional, and is available to help readability (reference), though a similar effect is achieved via aligning spaces on the start of the type, name, and description.
Usage seems a bit mixed throughout Calypso. In my own case, I'm using the Sublime Text 3 DocBlockr package, which does not add the hyphens and (as far as I can tell) does not offer an option to do so, so it's a bit more effort for me to revise. TL;DR: I'm lazy 😆
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.
:-D
btw I've added a @jsdoc suggestion. Feel free to ignore it. |
Now that you mention it, I think there is some opportunity to move bits of this to wpcom.js, though there'd still be need for a Calypso-specific override to achieve the "implicit" locale via current user settings. We could port the wpcom.withLocale( 'es' ).me().get();
// vs.
wpcom.me().get( { locale: 'es' } ); Maybe instead it could be part of a (new) initializer options object so that the a shared instance would always make requests with a particular locale? const wpcom = new WPCOM( { locale: 'es', token: '...' } );
wpcom.me().get();
wpcom.site( '...' ).get(); |
4004c18
to
aacb3b9
Compare
Framework: Add localization helpers to global wpcom instance
This pull request seeks to add a new
withLocale
helper function to the globalwpcom.js
instance used across Calypso. Specifically, this will enable opt-in localization of REST API requests for endpoints supported inwpcom.js
. This is similar to the_sendRequestWithLocale
method available to undocumented endpoints, but (a) applies to any and all requests made through thewpcom.js
instance and (b) leveragescurrentUser
Redux state in place of legacylib/user
methods.See included README.md for more information
Example usage:
Implementation notes:
This follows a very similar approach to the support user wrapping implemented by @jordwest in #2510.
Testing instructions:
No existing usage of the global
wpcom.js
have been migrated here to opt-in to the newwithLocale
function. Instead, ensure that existing usages remain unaffected by verifying that there are no console errors, and network requests do not include alocale
parameter (unless a custom implementation has been used).Also ensure that included Mocha tests pass by running
make test
from the project root directory or directly fromclient/state/current-user
andclient/lib/wp/localization
./cc @retrofox , @timmyc (re: #3264 (comment))