forked from geolonia/takamatsu-scratch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from MacareuxDigital/poc/modal-title-translation
POC: manually set language translation to "choose an extension" modal title
- Loading branch information
Showing
2 changed files
with
64 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from "react"; | ||
import {connect} from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const messagesEnglish = { | ||
"chooseExtensionModalTitle": "Optional Extensions for Your Project :)" | ||
} | ||
|
||
const messagesJapanese = { | ||
"chooseExtensionModalTitle": "プロジェクトのオプション拡張機能 :)" | ||
} | ||
|
||
const TranslationHOC = function(WrappedComponent) { | ||
class TranslationContainer extends React.PureComponent { | ||
constructor (props) { | ||
super(props); | ||
} | ||
state = { | ||
messages: {}, | ||
}; | ||
componentDidMount() { | ||
this.updateTranslation(); | ||
} | ||
componentDidUpdate(){ | ||
this.updateTranslation(); | ||
} | ||
updateTranslation = () => { | ||
if (this.props.currentLocale === 'ja') { | ||
this.setState({ | ||
messages: messagesJapanese, | ||
}); | ||
} else { | ||
this.setState({ | ||
messages: messagesEnglish, | ||
}); | ||
} | ||
} | ||
render () { | ||
return (<WrappedComponent | ||
messagesTranslation={this.state.messages} | ||
{...this.props} | ||
/>); | ||
} | ||
} | ||
TranslationContainer.propTypes = { | ||
currentLocale: PropTypes.string.isRequired, | ||
}; | ||
const mapStateToProps = state => { | ||
return { | ||
currentLocale: state.locales.locale, | ||
} | ||
} | ||
return connect( | ||
mapStateToProps, | ||
)(TranslationContainer); | ||
|
||
}; | ||
|
||
export default TranslationHOC; |