accounts-frontend/packages/app/components/languageSwitcher/changeLanguageLink/ChangeLanguageLink.tsx

42 lines
1.3 KiB
TypeScript
Raw Normal View History

import React, { ComponentType, useCallback } from 'react';
2019-12-08 01:13:08 +05:30
import clsx from 'clsx';
import { useReduxDispatch, useReduxSelector } from 'app/functions';
2020-07-20 17:49:15 +05:30
import { getLocaleIconUrl } from 'app/components/i18n';
import LANGS from 'app/i18n';
import { create as createPopup } from 'app/components/ui/popup/actions';
import LanguageSwitcher from 'app/components/languageSwitcher';
import styles from './link.scss';
const LanguageLink: ComponentType = () => {
const dispatch = useReduxDispatch();
2020-05-24 04:38:24 +05:30
const showLanguageSwitcherPopup = useCallback(() => {
dispatch(createPopup({ Popup: LanguageSwitcher }));
}, [dispatch]);
const userLang = useReduxSelector((state) => state.user.lang);
const interfaceLocale = useReduxSelector((state) => state.i18n.locale);
2020-05-24 04:38:24 +05:30
const localeDefinition = LANGS[userLang] || LANGS[interfaceLocale];
2020-05-24 04:38:24 +05:30
return (
<span
className={clsx(styles.languageLink, {
[styles.mark]: userLang !== interfaceLocale,
})}
onClick={showLanguageSwitcherPopup}
>
<span
className={styles.languageIcon}
style={{
2020-07-20 17:49:15 +05:30
backgroundImage: `url('${getLocaleIconUrl(localeDefinition.code)}')`,
2020-05-24 04:38:24 +05:30
}}
/>
{localeDefinition.name}
</span>
);
};
export default LanguageLink;