diff options
Diffstat (limited to 'modern/src')
18 files changed, 29 insertions, 34 deletions
diff --git a/modern/src/DevicePage.js b/modern/src/DevicePage.js index c3a49a5..def48d9 100644 --- a/modern/src/DevicePage.js +++ b/modern/src/DevicePage.js @@ -12,7 +12,7 @@ import deviceCategories from './common/deviceCategories'; import LinkField from './form/LinkField'; import { prefixString } from './common/stringUtils'; import { useTranslation } from './LocalizationProvider'; -import { useDeviceAttributes } from './attributes/deviceAttributes'; +import useDeviceAttributes from './attributes/useDeviceAttributes'; const useStyles = makeStyles(() => ({ details: { diff --git a/modern/src/GeofencePage.js b/modern/src/GeofencePage.js index db75246..d421a8e 100644 --- a/modern/src/GeofencePage.js +++ b/modern/src/GeofencePage.js @@ -8,7 +8,7 @@ import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; import EditItemView from './EditItemView'; import EditAttributesView from './attributes/EditAttributesView'; import { useTranslation } from './LocalizationProvider'; -import { useGeofenceAttributes } from './attributes/geofenceAttributes'; +import useGeofenceAttributes from './attributes/useGeofenceAttributes'; const useStyles = makeStyles(() => ({ details: { diff --git a/modern/src/LocalizationProvider.js b/modern/src/LocalizationProvider.js index ae08a56..cc23d72 100644 --- a/modern/src/LocalizationProvider.js +++ b/modern/src/LocalizationProvider.js @@ -1,5 +1,5 @@ import React, { createContext, useContext } from 'react'; -import { usePersistedState } from './common/usePersistedState'; +import usePersistedState from './common/usePersistedState'; import af from '../../web/l10n/af.json'; import ar from '../../web/l10n/ar.json'; @@ -38,7 +38,7 @@ import nl from '../../web/l10n/nl.json'; import nn from '../../web/l10n/nn.json'; import pl from '../../web/l10n/pl.json'; import pt from '../../web/l10n/pt.json'; -import pt_BR from '../../web/l10n/pt_BR.json'; +import ptBR from '../../web/l10n/pt_BR.json'; import ro from '../../web/l10n/ro.json'; import ru from '../../web/l10n/ru.json'; import si from '../../web/l10n/si.json'; @@ -54,7 +54,7 @@ import uk from '../../web/l10n/uk.json'; import uz from '../../web/l10n/uz.json'; import vi from '../../web/l10n/vi.json'; import zh from '../../web/l10n/zh.json'; -import zh_TW from '../../web/l10n/zh_TW.json'; +import zhTW from '../../web/l10n/zh_TW.json'; const languages = { af: { data: af, name: 'Afrikaans' }, @@ -94,7 +94,7 @@ const languages = { nn: { data: nn, name: 'Norsk nynorsk' }, pl: { data: pl, name: 'Polski' }, pt: { data: pt, name: 'Português' }, - pt_BR: { data: pt_BR, name: 'Português (Brasil)' }, + ptBR: { data: ptBR, name: 'Português (Brasil)' }, ro: { data: ro, name: 'Română' }, ru: { data: ru, name: 'Русский' }, si: { data: si, name: 'සිංහල' }, @@ -110,7 +110,7 @@ const languages = { uz: { data: uz, name: 'Oʻzbekcha' }, vi: { data: vi, name: 'Tiếng Việt' }, zh: { data: zh, name: '中文' }, - zh_TW: { data: zh_TW, name: '中文 (Taiwan)' }, + zhTW: { data: zhTW, name: '中文 (Taiwan)' }, }; const getDefaultLanguage = () => { @@ -118,10 +118,9 @@ const getDefaultLanguage = () => { const browserLanguage = window.navigator.userLanguage || window.navigator.language; browserLanguages.push(browserLanguage); browserLanguages.push(browserLanguage.substring(0, 2)); - browserLanguages.push('en'); - for (let i = 0; i < browserLanguages.length; i++) { - let language = browserLanguages[i].replace('-', '_'); + for (let i = 0; i < browserLanguages.length; i += 1) { + let language = browserLanguages[i].replace('-', ''); if (language in languages) { return language; } @@ -132,6 +131,7 @@ const getDefaultLanguage = () => { } } } + return 'en'; }; const LocalizationContext = createContext({ @@ -150,18 +150,16 @@ export const LocalizationProvider = ({ children }) => { ); }; -export const useLocalization = () => { - return useContext(LocalizationContext); -}; +export const useLocalization = () => useContext(LocalizationContext); export const useTranslation = () => { const context = useContext(LocalizationContext); - const data = context.languages[context.language].data; + const { data } = context.languages[context.language]; return (key) => data[key]; }; export const useTranslationKeys = (predicate) => { const context = useContext(LocalizationContext); - const data = context.languages[context.language].data; + const { data } = context.languages[context.language]; return Object.keys(data).filter(predicate); }; diff --git a/modern/src/UserPage.js b/modern/src/UserPage.js index 977d330..ec19dd6 100644 --- a/modern/src/UserPage.js +++ b/modern/src/UserPage.js @@ -9,7 +9,7 @@ import EditItemView from './EditItemView'; import EditAttributesView from './attributes/EditAttributesView'; import LinkField from './form/LinkField'; import { useTranslation } from './LocalizationProvider'; -import { useUserAttributes } from './attributes/userAttributes'; +import useUserAttributes from './attributes/useUserAttributes'; const useStyles = makeStyles(() => ({ details: { diff --git a/modern/src/admin/ServerPage.js b/modern/src/admin/ServerPage.js index b424aac..6f0d073 100644 --- a/modern/src/admin/ServerPage.js +++ b/modern/src/admin/ServerPage.js @@ -9,8 +9,8 @@ import { useHistory } from 'react-router-dom'; import { useDispatch, useSelector } from 'react-redux'; import { sessionActions } from '../store'; import EditAttributesView from '../attributes/EditAttributesView'; -import { useDeviceAttributes } from '../attributes/deviceAttributes'; -import { useUserAttributes } from '../attributes/userAttributes'; +import useDeviceAttributes from '../attributes/useDeviceAttributes'; +import useUserAttributes from '../attributes/useUserAttributes'; import OptionsLayout from '../settings/OptionsLayout'; import { useTranslation } from '../LocalizationProvider'; diff --git a/modern/src/attributes/deviceAttributes.js b/modern/src/attributes/useDeviceAttributes.js index 20bb1e0..3321321 100644 --- a/modern/src/attributes/deviceAttributes.js +++ b/modern/src/attributes/useDeviceAttributes.js @@ -1,6 +1,6 @@ import { useMemo } from 'react'; -export const useDeviceAttributes = (t) => useMemo({ +export default (t) => useMemo({ speedLimit: { name: t('attributeSpeedLimit'), type: 'string', diff --git a/modern/src/attributes/geofenceAttributes.js b/modern/src/attributes/useGeofenceAttributes.js index d9f512f..3c17755 100644 --- a/modern/src/attributes/geofenceAttributes.js +++ b/modern/src/attributes/useGeofenceAttributes.js @@ -1,6 +1,6 @@ import { useMemo } from 'react'; -export const useGeofenceAttributes = (t) => useMemo({ +export default (t) => useMemo({ speedLimit: { name: t('attributeSpeedLimit'), type: 'string', diff --git a/modern/src/attributes/positionAttributes.js b/modern/src/attributes/usePositionAttributes.js index 49a64f7..825ec36 100644 --- a/modern/src/attributes/positionAttributes.js +++ b/modern/src/attributes/usePositionAttributes.js @@ -1,6 +1,6 @@ import { useMemo } from 'react'; -export const usePositionAttributes = (t) => useMemo({ +export default (t) => useMemo({ raw: { name: t('positionRaw'), type: 'string', diff --git a/modern/src/attributes/userAttributes.js b/modern/src/attributes/useUserAttributes.js index d9a5814..bf8c95a 100644 --- a/modern/src/attributes/userAttributes.js +++ b/modern/src/attributes/useUserAttributes.js @@ -1,6 +1,6 @@ import { useMemo } from 'react'; -export const useUserAttributes = (t) => useMemo({ +export default (t) => useMemo({ notificationTokens: { name: t('attributeNotificationTokens'), type: 'string', diff --git a/modern/src/common/formatter.js b/modern/src/common/formatter.js index 7a18d1a..0ff4e74 100644 --- a/modern/src/common/formatter.js +++ b/modern/src/common/formatter.js @@ -1,9 +1,6 @@ import moment from 'moment'; -import { useTranslation } from '../LocalizationProvider'; -export const formatBoolean = (value, t) => { - return value ? t('sharedYes') : t('sharedNo'); -} +export const formatBoolean = (value, t) => (value ? t('sharedYes') : t('sharedNo')); export const formatNumber = (value, precision = 1) => Number(value.toFixed(precision)); diff --git a/modern/src/common/usePersistedState.js b/modern/src/common/usePersistedState.js index a3a60d7..0a7a990 100644 --- a/modern/src/common/usePersistedState.js +++ b/modern/src/common/usePersistedState.js @@ -1,7 +1,6 @@ import { useEffect, useState } from 'react'; -export const usePersistedState = (key, defaultValue) => { - +export default (key, defaultValue) => { const [value, setValue] = useState(() => { const stickyValue = window.localStorage.getItem(key); return stickyValue ? JSON.parse(stickyValue) : defaultValue; diff --git a/modern/src/map/Map.js b/modern/src/map/Map.js index 1fa4db5..2b95087 100644 --- a/modern/src/map/Map.js +++ b/modern/src/map/Map.js @@ -15,6 +15,7 @@ import palette from '../theme/palette'; // TODO fix localization import en from '../../../web/l10n/en.json'; + const t = (key) => en[key]; const element = document.createElement('div'); diff --git a/modern/src/reports/ChartReportPage.js b/modern/src/reports/ChartReportPage.js index 6679fe4..3639b98 100644 --- a/modern/src/reports/ChartReportPage.js +++ b/modern/src/reports/ChartReportPage.js @@ -39,7 +39,7 @@ const Filter = ({ children, setItems }) => { const ChartType = ({ type, setType }) => { const t = useTranslation(); - + return ( <Grid container spacing={3}> <Grid item xs={12} sm={6}> diff --git a/modern/src/settings/ComputedAttributePage.js b/modern/src/settings/ComputedAttributePage.js index 6733e98..e8efd09 100644 --- a/modern/src/settings/ComputedAttributePage.js +++ b/modern/src/settings/ComputedAttributePage.js @@ -5,7 +5,7 @@ import { import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; import EditItemView from '../EditItemView'; import { useTranslation } from '../LocalizationProvider'; -import { usePositionAttributes } from '../attributes/positionAttributes'; +import usePositionAttributes from '../attributes/usePositionAttributes'; const useStyles = makeStyles(() => ({ details: { diff --git a/modern/src/settings/GroupPage.js b/modern/src/settings/GroupPage.js index 88b9504..be14e96 100644 --- a/modern/src/settings/GroupPage.js +++ b/modern/src/settings/GroupPage.js @@ -7,7 +7,7 @@ import { import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; import EditItemView from '../EditItemView'; import EditAttributesView from '../attributes/EditAttributesView'; -import { useDeviceAttributes } from '../attributes/deviceAttributes'; +import useDeviceAttributes from '../attributes/useDeviceAttributes'; import SelectField from '../form/SelectField'; import { useTranslation } from '../LocalizationProvider'; diff --git a/modern/src/settings/MaintenancePage.js b/modern/src/settings/MaintenancePage.js index d9500be..c157ff4 100644 --- a/modern/src/settings/MaintenancePage.js +++ b/modern/src/settings/MaintenancePage.js @@ -12,7 +12,7 @@ import { speedFromKnots, speedToKnots, distanceFromMeters, distanceToMeters, } from '../common/converter'; import { useTranslation } from '../LocalizationProvider'; -import { usePositionAttributes } from '../attributes/positionAttributes'; +import usePositionAttributes from '../attributes/usePositionAttributes'; const useStyles = makeStyles(() => ({ details: { diff --git a/modern/src/settings/MaintenancesPage.js b/modern/src/settings/MaintenancesPage.js index 89b0279..2246b09 100644 --- a/modern/src/settings/MaintenancesPage.js +++ b/modern/src/settings/MaintenancesPage.js @@ -6,7 +6,7 @@ import MoreVertIcon from '@material-ui/icons/MoreVert'; import { useEffectAsync } from '../reactHelper'; import EditCollectionView from '../EditCollectionView'; -import { usePositionAttributes } from '../attributes/positionAttributes'; +import usePositionAttributes from '../attributes/usePositionAttributes'; import { formatDistance, formatSpeed } from '../common/formatter'; import { useAttributePreference } from '../common/preferences'; import OptionsLayout from './OptionsLayout'; diff --git a/modern/src/settings/NotificationPage.js b/modern/src/settings/NotificationPage.js index 6d895d0..67c4ee0 100644 --- a/modern/src/settings/NotificationPage.js +++ b/modern/src/settings/NotificationPage.js @@ -4,7 +4,7 @@ import { Accordion, AccordionSummary, AccordionDetails, makeStyles, Typography, FormControlLabel, Checkbox, } from '@material-ui/core'; import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; -import t, { findStringKeys, useTranslation, useTranslationKeys } from '../LocalizationProvider'; +import { useTranslation, useTranslationKeys } from '../LocalizationProvider'; import EditItemView from '../EditItemView'; import { prefixString, unprefixString } from '../common/stringUtils'; import SelectField from '../form/SelectField'; |