This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(settings page & language selector): separate language selector
- Loading branch information
kumikokashii
committed
May 27, 2020
1 parent
c35ab99
commit 8f2bc88
Showing
2 changed files
with
43 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import _ from 'lodash' | ||
import React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
import i18n, { resources } from '../../i18n' | ||
import SelectWithLabelFormGroup from './SelectWithLableFormGroup' | ||
|
||
const LanguageSelector = () => { | ||
const { t } = useTranslation() | ||
|
||
let languageOptions = Object.keys(resources).map((abbr) => ({ | ||
label: resources[abbr].name, | ||
value: abbr, | ||
})) | ||
languageOptions = _.sortBy(languageOptions, (o) => o.label) | ||
|
||
const onLanguageChange = (event: React.ChangeEvent<HTMLSelectElement>) => { | ||
const selected = event.target.value | ||
i18n.changeLanguage(selected) | ||
} | ||
|
||
return ( | ||
<SelectWithLabelFormGroup | ||
name="language" | ||
value={i18n.language} | ||
label={t('settings.language.label')} | ||
isEditable | ||
options={languageOptions} | ||
onChange={onLanguageChange} | ||
/> | ||
) | ||
} | ||
|
||
export default LanguageSelector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters