2020-01-18 02:07:52 +05:30
|
|
|
import React, { ComponentType, useCallback } from 'react';
|
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2019-12-08 01:13:08 +05:30
|
|
|
import clsx from 'clsx';
|
2019-12-08 00:32:00 +05:30
|
|
|
import { localeFlags } 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 { RootState } from 'app/reducers';
|
2019-06-30 19:02:50 +05:30
|
|
|
|
2017-12-31 03:08:54 +05:30
|
|
|
import styles from './link.scss';
|
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
const LanguageLink: ComponentType = () => {
|
2020-05-24 04:38:24 +05:30
|
|
|
const dispatch = useDispatch();
|
|
|
|
const showLanguageSwitcherPopup = useCallback(() => {
|
|
|
|
dispatch(createPopup({ Popup: LanguageSwitcher }));
|
|
|
|
}, [dispatch]);
|
2020-01-18 02:07:52 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
const userLang = useSelector((state: RootState) => state.user.lang);
|
|
|
|
const interfaceLocale = useSelector((state: RootState) => state.i18n.locale);
|
2019-06-30 19:02:50 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
const localeDefinition = LANGS[userLang] || LANGS[interfaceLocale];
|
2019-05-21 20:53:13 +05:30
|
|
|
|
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={{
|
|
|
|
backgroundImage: `url('${localeFlags.getIconUrl(localeDefinition.code)}')`,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{localeDefinition.name}
|
|
|
|
</span>
|
|
|
|
);
|
2020-01-18 02:07:52 +05:30
|
|
|
};
|
2017-12-31 03:08:54 +05:30
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
export default LanguageLink;
|