2020-01-18 02:07:52 +05:30
|
|
|
import { Action as ReduxAction } from 'redux';
|
2020-07-22 15:31:12 +05:30
|
|
|
|
2019-12-08 00:32:00 +05:30
|
|
|
import i18n from 'app/services/i18n';
|
2020-07-22 15:31:12 +05:30
|
|
|
import { Action as AppAction } from 'app/types';
|
2016-05-20 01:11:43 +05:30
|
|
|
|
2020-07-22 15:31:12 +05:30
|
|
|
export function setLocale(desiredLocale: string): AppAction<Promise<string>> {
|
2020-05-24 04:38:24 +05:30
|
|
|
return async (dispatch) => {
|
|
|
|
const locale = i18n.detectLanguage(desiredLocale);
|
2016-11-05 15:41:41 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
dispatch(_setLocale(locale));
|
2016-05-20 01:11:43 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
return locale;
|
|
|
|
};
|
2016-05-20 01:11:43 +05:30
|
|
|
}
|
2016-11-05 15:41:41 +05:30
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
interface SetAction extends ReduxAction {
|
2020-05-24 04:38:24 +05:30
|
|
|
type: 'i18n:setLocale';
|
|
|
|
payload: {
|
|
|
|
locale: string;
|
|
|
|
};
|
2020-01-18 02:07:52 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
function _setLocale(locale: string): SetAction {
|
2020-05-24 04:38:24 +05:30
|
|
|
return {
|
|
|
|
type: 'i18n:setLocale',
|
|
|
|
payload: {
|
|
|
|
locale,
|
|
|
|
},
|
|
|
|
};
|
2016-11-05 15:41:41 +05:30
|
|
|
}
|
2020-01-18 02:07:52 +05:30
|
|
|
|
|
|
|
export type Action = SetAction;
|