diff --git a/src/components/withLocalize.js b/src/components/withLocalize.js index 4eb5ca18d6d..a5fbb53e57d 100755 --- a/src/components/withLocalize.js +++ b/src/components/withLocalize.js @@ -44,17 +44,19 @@ const localeProviderDefaultProps = { }; class LocaleContextProvider extends React.Component { - constructor(props) { - super(props); - - /* The context this component exposes to consumers */ - this.translateUtils = { + /** + * The context this component exposes to child components + * @returns {object} translation util functions and locale + */ + getContextValue() { + return { translate: this.translate.bind(this), numberFormat: this.numberFormat.bind(this), timestampToRelative: this.timestampToRelative.bind(this), timestampToDateTime: this.timestampToDateTime.bind(this), fromLocalPhone: this.fromLocalPhone.bind(this), toLocalPhone: this.toLocalPhone.bind(this), + locale: this.props.preferredLocale, }; } @@ -115,7 +117,7 @@ class LocaleContextProvider extends React.Component { render() { return ( - + {this.props.children} ); @@ -137,7 +139,7 @@ export default function withLocalize(WrappedComponent) { const WithLocalize = forwardRef((props, ref) => ( {/* eslint-disable-next-line react/jsx-props-no-spreading */} - { translateUtils => } + {translateUtils => } ));