Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import React from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';
import MaterialSelect from '../MaterialSelect/MaterialSelect';
import i18n, { getLanguage } from '../../i18n';
class LanguageSelector extends React.Component {
constructor(props) {
super(props);
const lang = getLanguage();
this.state = {
selectedLanguage: lang,
};
}
handleChangeLanguage(event) {
i18n.changeLanguage(event.target.value);
this.setState({
selectedLanguage: event.target.value,
});
}
render() {
const { t } = this.props;
const languages = [
{ label: 'NL', value: 'nl' },
{ label: 'FR', value: 'fr' },
{ label: 'EN', value: 'en' },
];
const { selectedLanguage } = this.state;
return (
<MaterialSelect label={t('Language')} value={selectedLanguage} options={languages} handleChange={(event) => this.handleChangeLanguage(event)} />
);
}
}
LanguageSelector.propTypes = {
t: PropTypes.func.isRequired,
};
export default withTranslation()(LanguageSelector);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.