32 lines
681 B
TypeScript
Raw Normal View History

import { Action as ReduxAction } from 'redux';
import i18n from 'app/services/i18n';
import { ThunkAction } from 'app/reducers';
2016-05-19 22:41:43 +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
interface SetAction extends ReduxAction {
2020-05-24 02:08:24 +03:00
type: 'i18n:setLocale';
payload: {
locale: string;
};
}
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
}
export type Action = SetAction;