mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-05-31 14:11:58 +05:30
Change prettier rules
This commit is contained in:
@@ -5,23 +5,21 @@ import i18n from 'app/services/i18n';
|
||||
import { RootState } from 'app/reducers';
|
||||
|
||||
const IntlProvider: ComponentType = ({ children }) => {
|
||||
const [intl, setIntl] = useState<IntlShape>(i18n.getIntl());
|
||||
const locale = useSelector(
|
||||
({ i18n: i18nState }: RootState) => i18nState.locale,
|
||||
);
|
||||
const [intl, setIntl] = useState<IntlShape>(i18n.getIntl());
|
||||
const locale = useSelector(({ i18n: i18nState }: RootState) => i18nState.locale);
|
||||
|
||||
useEffect(() => {
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
// disable async modules loading in tests
|
||||
return;
|
||||
}
|
||||
useEffect(() => {
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
// disable async modules loading in tests
|
||||
return;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
setIntl(await i18n.changeLocale(locale));
|
||||
})();
|
||||
}, [locale]);
|
||||
(async () => {
|
||||
setIntl(await i18n.changeLocale(locale));
|
||||
})();
|
||||
}, [locale]);
|
||||
|
||||
return <RawIntlProvider value={intl}>{children}</RawIntlProvider>;
|
||||
return <RawIntlProvider value={intl}>{children}</RawIntlProvider>;
|
||||
};
|
||||
|
||||
export default IntlProvider;
|
||||
|
||||
@@ -3,29 +3,29 @@ import i18n from 'app/services/i18n';
|
||||
import { ThunkAction } from 'app/reducers';
|
||||
|
||||
export function setLocale(desiredLocale: string): ThunkAction<Promise<string>> {
|
||||
return async (dispatch) => {
|
||||
const locale = i18n.detectLanguage(desiredLocale);
|
||||
return async (dispatch) => {
|
||||
const locale = i18n.detectLanguage(desiredLocale);
|
||||
|
||||
dispatch(_setLocale(locale));
|
||||
dispatch(_setLocale(locale));
|
||||
|
||||
return locale;
|
||||
};
|
||||
return locale;
|
||||
};
|
||||
}
|
||||
|
||||
interface SetAction extends ReduxAction {
|
||||
type: 'i18n:setLocale';
|
||||
payload: {
|
||||
locale: string;
|
||||
};
|
||||
type: 'i18n:setLocale';
|
||||
payload: {
|
||||
locale: string;
|
||||
};
|
||||
}
|
||||
|
||||
function _setLocale(locale: string): SetAction {
|
||||
return {
|
||||
type: 'i18n:setLocale',
|
||||
payload: {
|
||||
locale,
|
||||
},
|
||||
};
|
||||
return {
|
||||
type: 'i18n:setLocale',
|
||||
payload: {
|
||||
locale,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export type Action = SetAction;
|
||||
|
||||
@@ -1,38 +1,34 @@
|
||||
import supportedLocales from 'app/i18n';
|
||||
|
||||
const localeToCountryCode: Record<string, string> = {
|
||||
en: 'gb',
|
||||
be: 'by',
|
||||
pt: 'br',
|
||||
uk: 'ua',
|
||||
vi: 'vn',
|
||||
sl: 'si',
|
||||
sr: 'rs',
|
||||
zh: 'cn',
|
||||
en: 'gb',
|
||||
be: 'by',
|
||||
pt: 'br',
|
||||
uk: 'ua',
|
||||
vi: 'vn',
|
||||
sl: 'si',
|
||||
sr: 'rs',
|
||||
zh: 'cn',
|
||||
};
|
||||
const SUPPORTED_LANGUAGES: string[] = Object.keys(supportedLocales);
|
||||
|
||||
export default {
|
||||
getCountryList(): string[] {
|
||||
return SUPPORTED_LANGUAGES.map(
|
||||
(locale) => localeToCountryCode[locale] || locale,
|
||||
);
|
||||
},
|
||||
getCountryList(): string[] {
|
||||
return SUPPORTED_LANGUAGES.map((locale) => localeToCountryCode[locale] || locale);
|
||||
},
|
||||
|
||||
/**
|
||||
* Возвращает для указанной локали её флаг с учётом всех нюансов загрузки флага
|
||||
* и подбора соответствующего локали флага.
|
||||
*
|
||||
* @param {string} locale
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
getIconUrl(locale: string): string {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const mod = require(`flag-icon-css/flags/4x3/${
|
||||
localeToCountryCode[locale] || locale
|
||||
}.svg`);
|
||||
/**
|
||||
* Возвращает для указанной локали её флаг с учётом всех нюансов загрузки флага
|
||||
* и подбора соответствующего локали флага.
|
||||
*
|
||||
* @param {string} locale
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
getIconUrl(locale: string): string {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const mod = require(`flag-icon-css/flags/4x3/${localeToCountryCode[locale] || locale}.svg`);
|
||||
|
||||
return mod.default || mod;
|
||||
},
|
||||
return mod.default || mod;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -3,20 +3,17 @@ import i18n from 'app/services/i18n';
|
||||
import { Action } from './actions';
|
||||
|
||||
export interface State {
|
||||
locale: string;
|
||||
locale: string;
|
||||
}
|
||||
|
||||
const defaultState: State = {
|
||||
locale: i18n.detectLanguage(),
|
||||
locale: i18n.detectLanguage(),
|
||||
};
|
||||
|
||||
export default function (
|
||||
state: State = defaultState,
|
||||
{ type, payload }: Action,
|
||||
): State {
|
||||
if (type === 'i18n:setLocale') {
|
||||
return payload;
|
||||
}
|
||||
export default function (state: State = defaultState, { type, payload }: Action): State {
|
||||
if (type === 'i18n:setLocale') {
|
||||
return payload;
|
||||
}
|
||||
|
||||
return state;
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user