2020-01-17 23:37:52 +03:00
|
|
|
import { Action as ReduxAction } from 'redux';
|
2019-12-07 21:02:00 +02:00
|
|
|
import i18n from 'app/services/i18n';
|
2020-01-17 23:37:52 +03:00
|
|
|
import { ThunkAction } from 'app/reducers';
|
2016-05-19 22:41:43 +03:00
|
|
|
|
2020-01-17 23:37:52 +03:00
|
|
|
export function setLocale(desiredLocale: string): ThunkAction<Promise<string>> {
|
2020-05-24 02:08:24 +03:00
|
|
|
return async (dispatch) => {
|
|
|
|
const locale = i18n.detectLanguage(desiredLocale);
|
2016-11-05 12:11:41 +02:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
dispatch(_setLocale(locale));
|
2016-05-19 22:41:43 +03:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
return locale;
|
|
|
|
};
|
2016-05-19 22:41:43 +03:00
|
|
|
}
|
2016-11-05 12:11:41 +02:00
|
|
|
|
2020-01-17 23:37:52 +03:00
|
|
|
interface SetAction extends ReduxAction {
|
2020-05-24 02:08:24 +03:00
|
|
|
type: 'i18n:setLocale';
|
|
|
|
payload: {
|
|
|
|
locale: string;
|
|
|
|
};
|
2020-01-17 23:37:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function _setLocale(locale: string): SetAction {
|
2020-05-24 02:08:24 +03:00
|
|
|
return {
|
|
|
|
type: 'i18n:setLocale',
|
|
|
|
payload: {
|
|
|
|
locale,
|
|
|
|
},
|
|
|
|
};
|
2016-11-05 12:11:41 +02:00
|
|
|
}
|
2020-01-17 23:37:52 +03:00
|
|
|
|
|
|
|
export type Action = SetAction;
|