2019-09-04 23:43:37 +02:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { FormField } from 'component/common/form';
|
|
|
|
import Spinner from 'component/spinner';
|
2020-10-15 19:56:55 +02:00
|
|
|
import SUPPORTED_LANGUAGES from 'constants/supported_languages';
|
2020-11-20 14:21:31 +01:00
|
|
|
import { getDefaultLanguage } from 'util/default-languages';
|
2019-09-04 23:43:37 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
language: string,
|
2019-11-05 19:54:58 +01:00
|
|
|
setLanguage: string => void,
|
2020-10-15 19:56:55 +02:00
|
|
|
searchInLanguage: boolean,
|
|
|
|
setSearchInLanguage: boolean => void,
|
2019-09-04 23:43:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function SettingLanguage(props: Props) {
|
2020-10-15 19:56:55 +02:00
|
|
|
const { language, setLanguage, searchInLanguage, setSearchInLanguage } = props;
|
2019-11-05 19:54:58 +01:00
|
|
|
|
|
|
|
const [previousLanguage, setPreviousLanguage] = useState(null);
|
2019-10-15 17:37:55 +02:00
|
|
|
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);
|
|
|
|
}
|
2019-09-04 23:43:37 +02:00
|
|
|
|
|
|
|
function onLanguageChange(e) {
|
|
|
|
const { value } = e.target;
|
2020-11-20 14:21:31 +01:00
|
|
|
setPreviousLanguage(language || getDefaultLanguage());
|
2019-11-05 19:54:58 +01:00
|
|
|
setLanguage(value);
|
2019-09-04 23:43:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<FormField
|
|
|
|
name="language_select"
|
|
|
|
type="select"
|
|
|
|
label={__('Language')}
|
|
|
|
onChange={onLanguageChange}
|
2020-11-20 14:21:31 +01:00
|
|
|
value={language || getDefaultLanguage()}
|
2019-09-04 23:43:37 +02:00
|
|
|
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" />}
|
2020-10-15 19:56:55 +02:00
|
|
|
<FormField
|
|
|
|
name="search-in-language"
|
|
|
|
type="checkbox"
|
|
|
|
label={__('Search only in this language by default')}
|
|
|
|
checked={searchInLanguage}
|
|
|
|
onChange={() => setSearchInLanguage(!searchInLanguage)}
|
|
|
|
/>
|
2019-09-04 23:43:37 +02:00
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SettingLanguage;
|