2016-05-20 01:11:43 +05:30
|
|
|
import i18n from 'services/i18n';
|
2016-11-05 15:41:41 +05:30
|
|
|
import captcha from 'services/captcha';
|
2016-05-20 01:11:43 +05:30
|
|
|
|
2016-11-05 15:41:41 +05:30
|
|
|
export const SET_LOCALE = 'i18n:setLocale';
|
2016-05-20 01:11:43 +05:30
|
|
|
export function setLocale(locale) {
|
|
|
|
return (dispatch) => i18n.require(
|
|
|
|
i18n.detectLanguage(locale)
|
|
|
|
).then(({locale, messages}) => {
|
2016-11-05 15:41:41 +05:30
|
|
|
dispatch(_setLocale({locale, messages}));
|
|
|
|
|
|
|
|
// TODO: probably should be moved from here, because it is a side effect
|
|
|
|
captcha.setLang(locale);
|
2016-05-20 01:11:43 +05:30
|
|
|
|
|
|
|
return locale;
|
|
|
|
});
|
|
|
|
}
|
2016-11-05 15:41:41 +05:30
|
|
|
|
|
|
|
function _setLocale({locale, messages}) {
|
|
|
|
return {
|
|
|
|
type: SET_LOCALE,
|
|
|
|
payload: {
|
|
|
|
locale,
|
|
|
|
messages
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|