From cf77784bef473dfa89cc5bb68f2e2fcfb76e6093 Mon Sep 17 00:00:00 2001 From: dhoko Date: Mon, 27 Jan 2020 12:48:15 +0100 Subject: [PATCH] Add lazy loader for translations --- containers/app/StandardPrivateApp.js | 12 ++---------- containers/app/StandardPublicApp.js | 5 ++--- containers/general/LanguageSection.js | 8 ++------ index.ts | 13 ++++++++++--- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/containers/app/StandardPrivateApp.js b/containers/app/StandardPrivateApp.js index 6e074b7f1..aec7a5be5 100644 --- a/containers/app/StandardPrivateApp.js +++ b/containers/app/StandardPrivateApp.js @@ -1,6 +1,6 @@ import React, { useState, useRef } from 'react'; import PropTypes from 'prop-types'; -import { EventManagerProvider, ModalsChildren, ThemeInjector } from 'react-components'; +import { EventManagerProvider, ModalsChildren, ThemeInjector, lazyLocales as locales } from 'react-components'; import EventModelListener from '../eventManager/EventModelListener'; import EventNotices from '../eventManager/EventNotices'; @@ -8,14 +8,7 @@ import LoaderPage from './LoaderPage'; import StandardPreload from './StandardPreload'; import ForceRefreshProvider from '../forceRefresh/Provider'; -const StandardPrivateApp = ({ - locales = {}, - onLogout, - openpgpConfig, - preloadModels = [], - eventModels = [], - children -}) => { +const StandardPrivateApp = ({ onLogout, openpgpConfig, preloadModels = [], eventModels = [], children }) => { const [loading, setLoading] = useState(true); const eventManagerRef = useRef(); @@ -52,7 +45,6 @@ const StandardPrivateApp = ({ StandardPrivateApp.propTypes = { onLogout: PropTypes.func.isRequired, children: PropTypes.node.isRequired, - locales: PropTypes.object, openpgpConfig: PropTypes.object, preloadModels: PropTypes.array, eventModels: PropTypes.array diff --git a/containers/app/StandardPublicApp.js b/containers/app/StandardPublicApp.js index 47b01662c..e8c59920a 100644 --- a/containers/app/StandardPublicApp.js +++ b/containers/app/StandardPublicApp.js @@ -1,11 +1,11 @@ import React, { useEffect, useState } from 'react'; -import { LoaderPage, GenericError, ModalsChildren } from 'react-components'; +import { LoaderPage, GenericError, ModalsChildren, lazyLocales as locales } from 'react-components'; import PropTypes from 'prop-types'; import { loadOpenPGP } from 'proton-shared/lib/openpgp'; import { getBrowserLocale, getClosestMatches } from 'proton-shared/lib/i18n/helper'; import loadLocale from 'proton-shared/lib/i18n/loadLocale'; -const StandardPublicApp = ({ locales = {}, openpgpConfig, children }) => { +const StandardPublicApp = ({ openpgpConfig, children }) => { const [loading, setLoading] = useState(true); const [error, setError] = useState(false); @@ -46,7 +46,6 @@ const StandardPublicApp = ({ locales = {}, openpgpConfig, children }) => { }; StandardPublicApp.propTypes = { - locales: PropTypes.object, openpgpConfig: PropTypes.object, children: PropTypes.node }; diff --git a/containers/general/LanguageSection.js b/containers/general/LanguageSection.js index 6c389b41e..a5e5d437d 100644 --- a/containers/general/LanguageSection.js +++ b/containers/general/LanguageSection.js @@ -1,12 +1,12 @@ import React from 'react'; import { c } from 'ttag'; -import PropTypes from 'prop-types'; import { SubTitle, Row, Field, Label, Select, + lazyLocales as locales, useApi, useConfig, useLoading, @@ -19,7 +19,7 @@ import { updateLocale } from 'proton-shared/lib/api/settings'; import loadLocale from 'proton-shared/lib/i18n/loadLocale'; import { getBrowserLocale, getClosestMatches } from 'proton-shared/lib/i18n/helper'; -const LanguageSection = ({ locales = {} }) => { +const LanguageSection = () => { const api = useApi(); const { call } = useEventManager(); const { LOCALES = {} } = useConfig(); @@ -70,8 +70,4 @@ const LanguageSection = ({ locales = {} }) => { ); }; -LanguageSection.propTypes = { - locales: PropTypes.object.isRequired -}; - export default LanguageSection; diff --git a/index.ts b/index.ts index 2d77a0c2e..b61c73335 100644 --- a/index.ts +++ b/index.ts @@ -326,11 +326,17 @@ export { default as AddFilterModal } from './containers/filters/AddFilterModal'; export { default as AddEmailToListModal } from './containers/filters/AddEmailToListModal'; export { default as StorageSpaceStatus } from './containers/sidebar/StorageSpaceStatus'; -export { default as OpenVPNConfigurationSection } from './containers/vpn/OpenVPNConfigurationSection/OpenVPNConfigurationSection'; +export { + default as OpenVPNConfigurationSection +} from './containers/vpn/OpenVPNConfigurationSection/OpenVPNConfigurationSection'; export { default as ProtonVPNClientsSection } from './containers/vpn/ProtonVPNClientsSection/ProtonVPNClientsSection'; export { default as OpenVPNAccountSection } from './containers/vpn/OpenVPNAccountSection/OpenVPNAccountSection'; -export { default as ProtonVPNResourcesSection } from './containers/vpn/ProtonVPNResourcesSection/ProtonVPNResourcesSection'; -export { default as ProtonVPNCredentialsSection } from './containers/vpn/ProtonVPNCredentialsSection/ProtonVPNCredentialsSection'; +export { + default as ProtonVPNResourcesSection +} from './containers/vpn/ProtonVPNResourcesSection/ProtonVPNResourcesSection'; +export { + default as ProtonVPNCredentialsSection +} from './containers/vpn/ProtonVPNCredentialsSection/ProtonVPNCredentialsSection'; export { useUser, useGetUser } from './hooks/useUser'; export { default as useUserVPN } from './hooks/useUserVPN'; @@ -383,3 +389,4 @@ export { default as TopNavbar } from './containers/app/TopNavbar'; export { default as LoaderPage } from './containers/app/LoaderPage'; export * from './helpers/component'; +export { default as lazyLocales } from './helpers/lazyLocales';