Skip to content

Latest commit

 

History

History
63 lines (48 loc) · 1.56 KB

MIGRATING.md

File metadata and controls

63 lines (48 loc) · 1.56 KB

Migrating from v1 to v2

  1. Replace references to setGlobalTranslations and setLocalTranslations with the new addTranslation action creator.
const globalJson = require('global.locale.json');
const welcomeJson = require('welcome.locale.json');

// this...
store.dispatch(setGlobalTranslations(globalJson));
store.dispatch(setLocalTranslations('welcome', welcomeJson));

// changes to...
store.dispatch(addTranslation(globalJson));
store.dispatch(addTranslation(welcomeJson));
  1. Use new getTranslate and getActiveLanguage selectors instead of localize for components that are already using connect.
const MyComponent = ({ translate, currentLanguage }) => <div>{ translate('greeting') }</div>;

const mapStateToProps = state => ({
  translate: getTranslate(state),
  currentLanguage: getActiveLanguage(state).code
});

export default connect(mapStateToProps)(MyComponent);
  1. If a component is not using connect, you can still use localize, but you will need to make the following updates.
const MyComponent = ({ translate }) => <div>{ translate('greeting') }</div>;

// this...
export default localize('welcome')(MyComponent);

// changes to...
export default localize(MyComponent);
  1. Update translation data format.
// old format 
{
  "en": {
    "title": "My Title",
    "desc": "My Description"
  },
  "fr": {
    "title": "My Title French",
    "desc": "My Description French"
  }
}

// new format
{
  "title": ["My Title", "My Title French"],
  "desc": ["My Description", "My Description French"]
}