localize(Component, [reducerName], [getStateSlice])

Deprecated

This feature will be removed in the next major version. See Add translations to components for recommended options.

Important

if your component is already using connect then you should use the getTranslate, and getActiveLanguage selectors instead of localize.

If you have a component that just needs access to translations, and nothing else then you can use the localize higher-order function. When you pass your Component to localize it will automatically add translate and currentLanguage to props.

Arguments:

name Type Description
Component ReactComponent The localeReducer slice of your state.
[reducerName] string If you added localeReducer with combineReducers then you will need to pass the reducerName to localize.
[getStateSlice] function An optional param that allows for adding custom logic for retrieving the state slice. See Can I use ImmutableJS? for usage example.

Returns:

A higher-order React component that adds translate and currentLanguage to props.

Usage:

const Greeting = ({ translate, currentLanguage }) => (
  <span>
    <h1>languageCode: { currentLanguage }</h1>
    <h2>{ translate('greeting', { name: 'Testy McTest' }) }</h2>
  </span>
);
export default localize(Greeting, 'locale');