mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-17 20:42:25 +03:00
Refactor i18n functions a bit
This commit is contained in:
parent
055c77b38c
commit
151f43b95f
@ -16,7 +16,7 @@ import { albumViewReducer } from './album/albumState'
|
||||
import customRoutes from './routes'
|
||||
import themeReducer from './personal/themeReducer'
|
||||
import createAdminStore from './store/createAdminStore'
|
||||
import i18nProvider from './i18nProvider'
|
||||
import { i18nProvider } from './i18n'
|
||||
|
||||
const history = createHashHistory()
|
||||
|
||||
|
4
ui/src/i18n/index.js
Normal file
4
ui/src/i18n/index.js
Normal file
@ -0,0 +1,4 @@
|
||||
import i18nProvider from './provider'
|
||||
import useGetLanguageChoices from './useGetLanguageChoices'
|
||||
|
||||
export { i18nProvider, useGetLanguageChoices }
|
@ -1,5 +1,4 @@
|
||||
import polyglotI18nProvider from 'ra-i18n-polyglot'
|
||||
import { useGetList } from 'react-admin'
|
||||
import deepmerge from 'deepmerge'
|
||||
import dataProvider from '../dataProvider'
|
||||
import en from './en.json'
|
||||
@ -36,7 +35,7 @@ const prepareLanguage = (lang) => {
|
||||
return deepmerge(en, lang)
|
||||
}
|
||||
|
||||
const i18nProvider = polyglotI18nProvider((locale) => {
|
||||
export default polyglotI18nProvider((locale) => {
|
||||
// English is bundled
|
||||
if (locale === 'en') {
|
||||
return prepareLanguage(en)
|
||||
@ -52,23 +51,3 @@ const i18nProvider = polyglotI18nProvider((locale) => {
|
||||
return prepareLanguage(JSON.parse(res.data.data))
|
||||
})
|
||||
}, defaultLocale())
|
||||
|
||||
export default i18nProvider
|
||||
|
||||
// React Hook to get a list of all languages available. English is hardcoded
|
||||
export const useGetLanguageChoices = () => {
|
||||
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 }
|
||||
}
|
19
ui/src/i18n/useGetLanguageChoices.js
Normal file
19
ui/src/i18n/useGetLanguageChoices.js
Normal 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 }
|
||||
}
|
@ -14,7 +14,7 @@ import HelpOutlineIcon from '@material-ui/icons/HelpOutline'
|
||||
import { changeTheme } from './actions'
|
||||
import themes from '../themes'
|
||||
import { docsUrl } from '../utils/docsUrl'
|
||||
import { useGetLanguageChoices } from '../i18nProvider'
|
||||
import { useGetLanguageChoices } from '../i18n'
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: { marginTop: '1em' },
|
||||
|
Loading…
x
Reference in New Issue
Block a user