2017-12-31 03:08:54 +05:30
|
|
|
import React from 'react';
|
2019-05-21 20:53:13 +05:30
|
|
|
import classNames from 'classnames';
|
2019-12-08 00:32:00 +05:30
|
|
|
import { localeFlags } from 'app/components/i18n';
|
|
|
|
import LANGS from 'app/i18n';
|
2019-06-30 19:02:50 +05:30
|
|
|
import { connect } from 'react-redux';
|
2019-12-08 00:32:00 +05:30
|
|
|
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';
|
|
|
|
|
2019-06-30 19:02:50 +05:30
|
|
|
type Props = {
|
2019-12-07 16:58:52 +05:30
|
|
|
userLang: string;
|
|
|
|
interfaceLocale: string;
|
|
|
|
showLanguageSwitcherPopup: (event: React.MouseEvent<HTMLSpanElement>) => void;
|
2019-06-30 19:02:50 +05:30
|
|
|
};
|
|
|
|
|
2017-12-31 03:08:54 +05:30
|
|
|
function LanguageLink({
|
2019-11-27 14:33:32 +05:30
|
|
|
userLang,
|
|
|
|
interfaceLocale,
|
|
|
|
showLanguageSwitcherPopup,
|
2019-06-30 19:02:50 +05:30
|
|
|
}: Props) {
|
2019-11-27 14:33:32 +05:30
|
|
|
const localeDefinition = LANGS[userLang] || LANGS[interfaceLocale];
|
2019-05-21 20:53:13 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return (
|
|
|
|
<span
|
|
|
|
className={classNames(styles.languageLink, {
|
|
|
|
[styles.mark]: userLang !== interfaceLocale,
|
|
|
|
})}
|
|
|
|
onClick={showLanguageSwitcherPopup}
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
className={styles.languageIcon}
|
|
|
|
style={{
|
|
|
|
backgroundImage: `url('${localeFlags.getIconUrl(
|
|
|
|
localeDefinition.code,
|
|
|
|
)}')`,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{localeDefinition.name}
|
|
|
|
</span>
|
|
|
|
);
|
2017-12-31 03:08:54 +05:30
|
|
|
}
|
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
export default connect(
|
|
|
|
(state: RootState) => ({
|
2017-12-31 03:08:54 +05:30
|
|
|
userLang: state.user.lang,
|
2019-05-21 20:53:13 +05:30
|
|
|
interfaceLocale: state.i18n.locale,
|
2019-11-27 14:33:32 +05:30
|
|
|
}),
|
|
|
|
{
|
2019-06-30 19:02:50 +05:30
|
|
|
showLanguageSwitcherPopup: () => createPopup({ Popup: LanguageSwitcher }),
|
2019-11-27 14:33:32 +05:30
|
|
|
},
|
|
|
|
)(LanguageLink);
|