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';
|
2021-06-07 03:54:39 +02:00
|
|
|
import { getDefaultLanguage, sortLanguageMap } from 'util/default-languages';
|
2019-09-04 23:43:37 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
language: string,
|
2021-04-05 06:43:42 +02:00
|
|
|
setLanguage: (string) => void,
|
2020-10-15 19:56:55 +02:00
|
|
|
searchInLanguage: boolean,
|
2021-04-05 06:43:42 +02:00
|
|
|
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-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.'
|
|
|
|
)}
|
|
|
|
>
|
2021-06-07 03:54:39 +02:00
|
|
|
{sortLanguageMap(SUPPORTED_LANGUAGES).map(([langKey, langName]) => (
|
|
|
|
<option key={langKey} value={langKey}>
|
|
|
|
{langName}
|
|
|
|
</option>
|
|
|
|
))}
|
2019-09-04 23:43:37 +02:00
|
|
|
</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;
|