quintodrome/ui/src/i18n/useGetLanguageChoices.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

22 lines
576 B
JavaScript
Raw Normal View History

2020-05-02 13:44:24 -08:00
// React Hook to get a list of all languages available. English is hardcoded
import { useGetList } from 'react-admin'
const useGetLanguageChoices = () => {
2020-05-02 13:44:24 -08:00
const { ids, data, loaded, loading } = useGetList(
'translation',
{ page: 1, perPage: -1 },
{ field: '', order: '' },
{}
)
const choices = [{ id: 'en', name: 'English' }]
if (loaded) {
ids.forEach((id) => choices.push({ id: id, name: data[id].name }))
}
choices.sort((a, b) => a.name.localeCompare(b.name))
return { choices, loaded, loading }
}
export default useGetLanguageChoices