Skip to content

Conversation

@chrisgarrity
Copy link
Contributor

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 TitledHOC could not use injectIntl, 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:

  • Can switch languages
  • Can load in a different language (e.g. use ?locale=fr on the URL)
  • Can change the project title
  • The default project title is translated into other languages

Browser Coverage

Check the OS/browser combinations tested (At least 2)

Mac

  • Chrome
  • Firefox
  • Safari

Windows

  • Chrome
  • Firefox
  • Edge

Chromebook

  • Chrome

iPad

  • Safari

Android Tablet

  • Chrome

Copy link
Contributor

@rschamp rschamp left a 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.

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.
@chrisgarrity chrisgarrity force-pushed the issue/www2172-integrate-intl branch from ce55e7e to 8136ac4 Compare October 19, 2018 20:57
id: 'gui.sharedMessages.pop'
},
defaultProjectTitle: {
id: 'gui.gui.defaultProjectTitle',

This comment was marked as abuse.

This comment was marked as abuse.

Copy link
Contributor

@benjiwheeler benjiwheeler left a 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.

*/
const LocalizationHOC = function (WrappedComponent) {
class LocalizationWrapper extends React.Component {
componentDidUpdate (prevProps) {

This comment was marked as abuse.

This comment was marked as abuse.

]);
this.state = {
projectTitle: this.props.intl.formatMessage(defaultProjectTitleMessages.defaultProjectTitle)
projectTitle: ''

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

Copy link
Contributor

@benjiwheeler benjiwheeler left a 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.

*/
const LocalizationHOC = function (WrappedComponent) {
class LocalizationWrapper extends React.Component {
componentDidUpdate (prevProps) {

This comment was marked as abuse.

@benjiwheeler benjiwheeler removed their assignment Oct 22, 2018
@chrisgarrity chrisgarrity dismissed rschamp’s stale review October 22, 2018 15:38

Addressed in changes

@chrisgarrity chrisgarrity merged commit 92d51a5 into scratchfoundation:develop Oct 22, 2018
@chrisgarrity chrisgarrity deleted the issue/www2172-integrate-intl branch October 22, 2018 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants