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-06-30 19:02:50 +05:30
|
|
|
type OwnProps = {|
|
|
|
|
|};
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
...OwnProps,
|
|
|
|
userLang: string;
|
|
|
|
interfaceLocale: string;
|
|
|
|
showLanguageSwitcherPopup: Function;
|
|
|
|
};
|
|
|
|
|
2017-12-31 03:08:54 +05:30
|
|
|
function LanguageLink({
|
|
|
|
userLang,
|
2019-05-21 20:53:13 +05:30
|
|
|
interfaceLocale,
|
2017-12-31 03:08:54 +05:30
|
|
|
showLanguageSwitcherPopup,
|
2019-06-30 19:02:50 +05:30
|
|
|
}: Props) {
|
2019-05-21 20:53:13 +05:30
|
|
|
const localeDefinition = LANGS[userLang] || LANGS[interfaceLocale];
|
|
|
|
|
2017-12-31 03:08:54 +05:30
|
|
|
return (
|
2019-05-21 20:53:13 +05:30
|
|
|
<span
|
|
|
|
className={classNames(styles.languageLink, {
|
|
|
|
[styles.mark]: userLang !== interfaceLocale,
|
|
|
|
})}
|
|
|
|
onClick={showLanguageSwitcherPopup}
|
|
|
|
>
|
2017-12-31 03:08:54 +05:30
|
|
|
<span className={styles.languageIcon} style={{
|
2019-05-21 20:53:13 +05:30
|
|
|
backgroundImage: `url('${localeFlags.getIconUrl(localeDefinition.code)}')`,
|
2017-12-31 03:08:54 +05:30
|
|
|
}} />
|
2019-05-21 20:53:13 +05:30
|
|
|
{localeDefinition.name}
|
2017-12-31 03:08:54 +05:30
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-30 19:02:50 +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,
|
2017-12-31 03:08:54 +05:30
|
|
|
}), {
|
2019-06-30 19:02:50 +05:30
|
|
|
showLanguageSwitcherPopup: () => createPopup({ Popup: LanguageSwitcher }),
|
2017-12-31 03:08:54 +05:30
|
|
|
})(LanguageLink);
|