forked from rmdort/react-redux-multilingual
-
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.
- Loading branch information
Showing
10 changed files
with
112 additions
and
68 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
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,19 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.TranslateConsumer = exports.TranslateProvider = undefined; | ||
|
||
var _react = require('react'); | ||
|
||
var _react2 = _interopRequireDefault(_react); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
var TranslateContext = _react2.default.createContext(null); | ||
var TranslateProvider = TranslateContext.Provider, | ||
TranslateConsumer = TranslateContext.Consumer; | ||
exports.TranslateProvider = TranslateProvider; | ||
exports.TranslateConsumer = TranslateConsumer; | ||
exports.default = TranslateContext; |
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
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,10 @@ | ||
import React from 'react' | ||
|
||
const TranslateContext = React.createContext(null) | ||
const { | ||
Provider: TranslateProvider, | ||
Consumer: TranslateConsumer | ||
} = TranslateContext | ||
|
||
export { TranslateProvider, TranslateConsumer } | ||
export default TranslateContext |
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 |
---|---|---|
@@ -1,18 +1,17 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import hoistNonReactStatics from 'hoist-non-react-statics' | ||
import { TranslateConsumer } from './context' | ||
|
||
const getComponentDisplayName = (WrappedComponent) => { | ||
return WrappedComponent.displayName || WrappedComponent.name || 'Component' | ||
/** | ||
* Access translate function | ||
* @param {Object} WrappedComponent | ||
* @return {Object} | ||
*/ | ||
function withTranslate (WrappedComponent) { | ||
return (props) => ( | ||
<TranslateConsumer> | ||
{(translate) => <WrappedComponent {...props} translate={translate} />} | ||
</TranslateConsumer> | ||
) | ||
} | ||
|
||
export default (WrappedComponent) => { | ||
const WithTranslate = (props, context) => { | ||
return <WrappedComponent {...props} translate={context.translate} /> | ||
} | ||
WithTranslate.displayName = `withTranslate(${getComponentDisplayName(WrappedComponent)})` | ||
WithTranslate.contextTypes = { | ||
translate: PropTypes.func | ||
} | ||
return hoistNonReactStatics(WithTranslate, WrappedComponent) | ||
} | ||
export default withTranslate |