Skip to content

🎧 Your Personal Streaming Service

Refactor i18n functions a bit

Deluan151f43b95f08
diff --git a/ui/src/App.js b/ui/src/App.js
index fa23b54fc..3f8f43b37 100644
--- a/ui/src/App.js
+++ b/ui/src/App.js
@@ -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()
diff --git a/ui/src/i18nProvider/en.json b/ui/src/i18n/en.json
similarity index 100%
rename from ui/src/i18nProvider/en.json
rename to ui/src/i18n/en.json
diff --git a/ui/src/i18n/index.js b/ui/src/i18n/index.js
new file mode 100644
index 000000000..100aae8b8
--- /dev/null
+++ b/ui/src/i18n/index.js
@@ -0,0 +1,4 @@
+import i18nProvider from './provider'
+import useGetLanguageChoices from './useGetLanguageChoices'
+
+export { i18nProvider, useGetLanguageChoices }
diff --git a/ui/src/i18nProvider/index.js b/ui/src/i18n/provider.js
similarity index 71%
rename from ui/src/i18nProvider/index.js
rename to ui/src/i18n/provider.js
index 2e0d65469..69e125daf 100644
--- a/ui/src/i18nProvider/index.js
+++ b/ui/src/i18n/provider.js
@@ -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 }
-}
diff --git a/ui/src/i18n/useGetLanguageChoices.js b/ui/src/i18n/useGetLanguageChoices.js
new file mode 100644
index 000000000..3cf62673a
--- /dev/null
+++ b/ui/src/i18n/useGetLanguageChoices.js
@@ -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 }
+}
diff --git a/ui/src/personal/Personal.js b/ui/src/personal/Personal.js
index ea6d12d14..18a39b666 100644
--- a/ui/src/personal/Personal.js
+++ b/ui/src/personal/Personal.js
@@ -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' },