-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Localize all selects by passing a translation key as label (#1128)
Co-authored-by: Pierre-Gilles Leymarie <pierregilles.leymarie@gmail.com>
- Loading branch information
1 parent
8f834fe
commit e3f62e7
Showing
6 changed files
with
48 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,21 @@ | ||
import Select from 'react-select'; | ||
import { useText } from 'preact-i18n'; | ||
|
||
export const LocalizedSelect = props => { | ||
const translatedLabels = useText( | ||
(props.options || []).reduce((acc, option, index) => { | ||
// we use the index as the key rather than the value | ||
// this is in case two options have the same value but differing labels | ||
acc[index] = option.label; | ||
return acc; | ||
}, {}) | ||
); | ||
|
||
const options = (props.options || []).map((option, index) => ({ | ||
value: option.value, | ||
label: translatedLabels[index] | ||
})); | ||
return <Select {...{ ...props, options }} />; | ||
}; | ||
|
||
export default LocalizedSelect; |
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
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
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