Skip to content

Commit

Permalink
Prevented router components from sworking twice
Browse files Browse the repository at this point in the history
  • Loading branch information
batamar committed Aug 26, 2018
1 parent 461a157 commit 3c7b6df
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/modules/layout/containers/MainLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ class MainLayoutContainer extends React.Component {
constructor(props) {
super(props);

this.state = {
currentLanguage: 'en'
};
// initiliaze locale ======
const currentLanguage = localStorage.getItem('currentLanguage') || 'en';

this.state = { currentLanguage };
this.setLocale = this.setLocale.bind(this);
this.changeLanguage = this.changeLanguage.bind(this);

this.setLocale(currentLanguage);
}

getChildContext() {
Expand All @@ -81,18 +84,17 @@ class MainLayoutContainer extends React.Component {
};
}

componentDidMount() {
this.changeLanguage(localStorage.getItem('currentLanguage'));
setLocale(currentLanguage) {
moment.locale(currentLanguage);
T.setTexts(translations[currentLanguage]);
}

changeLanguage(languageCode) {
const currentLanguage = languageCode || 'en';

localStorage.setItem('currentLanguage', currentLanguage);

moment.locale(currentLanguage);

T.setTexts(translations[currentLanguage]);
this.setLocale(currentLanguage);

this.setState({ currentLanguage });
}
Expand Down

0 comments on commit 3c7b6df

Please sign in to comment.