Refactor i18n functions a bit

This commit is contained in:
Deluan
2020-05-02 17:44:24 -04:00
parent 055c77b38c
commit 151f43b95f
6 changed files with 26 additions and 24 deletions
+19
View File
@@ -0,0 +1,19 @@
// React Hook to get a list of all languages available. English is hardcoded
import { useGetList } from 'react-admin'
export default () => {
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 }
}