accounts-frontend/packages/app/components/i18n/actions.ts

33 lines
685 B
TypeScript
Raw Normal View History

import { Action as ReduxAction } from 'redux';
import i18n from 'app/services/i18n';
import { Action as AppAction } from 'app/types';
2016-05-20 01:11:43 +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
interface SetAction extends ReduxAction {
2020-05-24 04:38:24 +05:30
type: 'i18n:setLocale';
payload: {
locale: string;
};
}
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
}
export type Action = SetAction;