2017-12-31 03:08:54 +05:30
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
2019-05-21 20:53:13 +05:30
|
|
|
import classNames from 'classnames';
|
2017-12-31 03:08:54 +05:30
|
|
|
import { localeFlags } from 'components/i18n';
|
|
|
|
import LANGS from 'i18n/index.json';
|
2019-06-30 19:02:50 +05:30
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { create as createPopup } from 'components/ui/popup/actions';
|
|
|
|
import LanguageSwitcher from 'components/languageSwitcher';
|
|
|
|
|
2017-12-31 03:08:54 +05:30
|
|
|
import styles from './link.scss';
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
type OwnProps = {||};
|
2019-06-30 19:02:50 +05:30
|
|
|
|
|
|
|
type Props = {
|
2019-11-27 14:33:32 +05:30
|
|
|
...OwnProps,
|
|
|
|
userLang: string,
|
|
|
|
interfaceLocale: string,
|
|
|
|
showLanguageSwitcherPopup: Function,
|
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-11-27 14:33:32 +05:30
|
|
|
export default connect<Props, OwnProps, _, _, _, _>(
|
|
|
|
state => ({
|
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);
|