lbry-desktop/ui/component/settingLanguage/view.jsx

63 lines
1.8 KiB
React
Raw Normal View History

// @flow
import React, { useState } from 'react';
import { FormField } from 'component/common/form';
import Spinner from 'component/spinner';
import SUPPORTED_LANGUAGES from 'constants/supported_languages';
import { getDefaultLanguage } from 'util/default-languages';
type Props = {
language: string,
2019-11-05 19:54:58 +01:00
setLanguage: string => void,
searchInLanguage: boolean,
setSearchInLanguage: boolean => void,
};
function SettingLanguage(props: Props) {
const { language, setLanguage, searchInLanguage, setSearchInLanguage } = props;
2019-11-05 19:54:58 +01:00
const [previousLanguage, setPreviousLanguage] = useState(null);
const languages = SUPPORTED_LANGUAGES;
2019-10-03 18:55:21 +02:00
2019-11-05 19:54:58 +01:00
if (previousLanguage && language !== previousLanguage) {
setPreviousLanguage(null);
}
function onLanguageChange(e) {
const { value } = e.target;
setPreviousLanguage(language || getDefaultLanguage());
2019-11-05 19:54:58 +01:00
setLanguage(value);
}
return (
<React.Fragment>
<FormField
name="language_select"
type="select"
label={__('Language')}
onChange={onLanguageChange}
value={language || getDefaultLanguage()}
helper={__(
'Multi-language support is brand new and incomplete. Switching your language may have unintended consequences, like glossolalia.'
)}
>
{Object.keys(languages).map(language => (
<option key={language} value={language}>
{languages[language]}
</option>
))}
</FormField>
2019-11-05 19:54:58 +01:00
{previousLanguage && <Spinner type="small" />}
<FormField
name="search-in-language"
type="checkbox"
label={__('Search only in this language by default')}
checked={searchInLanguage}
onChange={() => setSearchInLanguage(!searchInLanguage)}
/>
</React.Fragment>
);
}
export default SettingLanguage;