-
Notifications
You must be signed in to change notification settings - Fork 4k
Refactor IntlProvider in GUI to support integration with www #3431
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
Refactor IntlProvider in GUI to support integration with www #3431
Conversation
rschamp
left a 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.
I think in general this is good, there is just a question of what to do about the defaultProjectTitle message.
c6c82f3 to
ce55e7e
Compare
This is taking advantage of the fact that react-intl can support nested IntlProviders. GUI will use it’s own ConnectedIntlProvider, that maintains the translations in redux, while www will continue to have it’s own IntlProvider that is initialized when the page loads. Moving the IntlProvider into GUI meant that nothing in the playground can use injectIntl, so the default project name needed to move into the component instead of being in the reducer. The Localization HOC is added, it takes an optional onSetLanguage handler, so www can pass a function that will set the cookie that www needs.
ce55e7e to
8136ac4
Compare
src/lib/shared-messages.js
Outdated
| id: 'gui.sharedMessages.pop' | ||
| }, | ||
| defaultProjectTitle: { | ||
| id: 'gui.gui.defaultProjectTitle', |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
benjiwheeler
left a 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.
This looks great, I just think we should hardcode the default English title ('Scratch Project') back in titled-hoc, and take sharedMessages.defaultProjectTitle out of the project-title-input's value prop.
| tabIndex="0" | ||
| type="text" | ||
| value={this.props.projectTitle} | ||
| value={this.props.projectTitle ? |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
| */ | ||
| const LocalizationHOC = function (WrappedComponent) { | ||
| class LocalizationWrapper extends React.Component { | ||
| componentDidUpdate (prevProps) { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
src/lib/titled-hoc.jsx
Outdated
| ]); | ||
| this.state = { | ||
| projectTitle: this.props.intl.formatMessage(defaultProjectTitleMessages.defaultProjectTitle) | ||
| projectTitle: '' |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
benjiwheeler
left a 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.
Looks great, thanks!
|
|
||
| import GUIComponent from '../components/gui/gui.jsx'; | ||
|
|
||
| const messages = defineMessages({ |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
| */ | ||
| const LocalizationHOC = function (WrappedComponent) { | ||
| class LocalizationWrapper extends React.Component { | ||
| componentDidUpdate (prevProps) { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Resolves
Required for scratchfoundation/scratch-www#2172
Proposed Changes
This is taking advantage of the fact that react-intl can support nested IntlProviders. GUI will use it’s own ConnectedIntlProvider, that maintains the translations in redux, while www will continue to have it’s own IntlProvider that is initialized when the page loads.
Moving the IntlProvider into GUI means that nothing in the playground can use injectIntl. As a result
TitledHOCcould not useinjectIntl, and the localization of the default project name needed to be moved into the component.The Localization HOC is added, it takes an optional onSetLanguage handler, so www can pass a function that will set the cookie that www needs.
Reason for Changes
Allow localization of GUI when embedded in www
Test Coverage
Current tests run: these changes should not have any impact on stand-alone GUI.
Manual Testing:
?locale=fron the URL)Browser Coverage
Check the OS/browser combinations tested (At least 2)
Mac
Windows
Chromebook
iPad
Android Tablet