Fixed: Improve translation loading

(cherry picked from commit 73c5ec1da4dd00301e1b0dddbcea37590a99b045)

Closes #3895
pull/4058/head
Mark McDowall 11 months ago committed by Bogdan
parent d473752999
commit 6c9ee67e51

@ -7,13 +7,13 @@ import PageConnector from 'Components/Page/PageConnector';
import ApplyTheme from './ApplyTheme'; import ApplyTheme from './ApplyTheme';
import AppRoutes from './AppRoutes'; import AppRoutes from './AppRoutes';
function App({ store, history, hasTranslationsError }) { function App({ store, history }) {
return ( return (
<DocumentTitle title={window.Lidarr.instanceName}> <DocumentTitle title={window.Lidarr.instanceName}>
<Provider store={store}> <Provider store={store}>
<ConnectedRouter history={history}> <ConnectedRouter history={history}>
<ApplyTheme> <ApplyTheme>
<PageConnector hasTranslationsError={hasTranslationsError}> <PageConnector>
<AppRoutes app={App} /> <AppRoutes app={App} />
</PageConnector> </PageConnector>
</ApplyTheme> </ApplyTheme>
@ -25,8 +25,7 @@ function App({ store, history, hasTranslationsError }) {
App.propTypes = { App.propTypes = {
store: PropTypes.object.isRequired, store: PropTypes.object.isRequired,
history: PropTypes.object.isRequired, history: PropTypes.object.isRequired
hasTranslationsError: PropTypes.bool.isRequired
}; };
export default App; export default App;

@ -7,7 +7,7 @@ function ErrorPage(props) {
const { const {
version, version,
isLocalStorageSupported, isLocalStorageSupported,
hasTranslationsError, translationsError,
artistError, artistError,
customFiltersError, customFiltersError,
tagsError, tagsError,
@ -21,8 +21,8 @@ function ErrorPage(props) {
if (!isLocalStorageSupported) { if (!isLocalStorageSupported) {
errorMessage = 'Local Storage is not supported or disabled. A plugin or private browsing may have disabled it.'; errorMessage = 'Local Storage is not supported or disabled. A plugin or private browsing may have disabled it.';
} else if (hasTranslationsError) { } else if (translationsError) {
errorMessage = 'Failed to load translations from API'; errorMessage = getErrorMessage(translationsError, 'Failed to load translations from API');
} else if (artistError) { } else if (artistError) {
errorMessage = getErrorMessage(artistError, 'Failed to load artist from API'); errorMessage = getErrorMessage(artistError, 'Failed to load artist from API');
} else if (customFiltersError) { } else if (customFiltersError) {
@ -55,7 +55,7 @@ function ErrorPage(props) {
ErrorPage.propTypes = { ErrorPage.propTypes = {
version: PropTypes.string.isRequired, version: PropTypes.string.isRequired,
isLocalStorageSupported: PropTypes.bool.isRequired, isLocalStorageSupported: PropTypes.bool.isRequired,
hasTranslationsError: PropTypes.bool.isRequired, translationsError: PropTypes.object,
artistError: PropTypes.object, artistError: PropTypes.object,
customFiltersError: PropTypes.object, customFiltersError: PropTypes.object,
tagsError: PropTypes.object, tagsError: PropTypes.object,

@ -3,7 +3,7 @@ import React, { Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom'; import { withRouter } from 'react-router-dom';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { saveDimensions, setIsSidebarVisible } from 'Store/Actions/appActions'; import { fetchTranslations, saveDimensions, setIsSidebarVisible } from 'Store/Actions/appActions';
import { fetchArtist } from 'Store/Actions/artistActions'; import { fetchArtist } from 'Store/Actions/artistActions';
import { fetchCustomFilters } from 'Store/Actions/customFilterActions'; import { fetchCustomFilters } from 'Store/Actions/customFilterActions';
import { fetchImportLists, fetchLanguages, fetchMetadataProfiles, fetchQualityProfiles, fetchUISettings } from 'Store/Actions/settingsActions'; import { fetchImportLists, fetchLanguages, fetchMetadataProfiles, fetchQualityProfiles, fetchUISettings } from 'Store/Actions/settingsActions';
@ -51,6 +51,7 @@ const selectIsPopulated = createSelector(
(state) => state.settings.metadataProfiles.isPopulated, (state) => state.settings.metadataProfiles.isPopulated,
(state) => state.settings.importLists.isPopulated, (state) => state.settings.importLists.isPopulated,
(state) => state.system.status.isPopulated, (state) => state.system.status.isPopulated,
(state) => state.app.translations.isPopulated,
( (
customFiltersIsPopulated, customFiltersIsPopulated,
tagsIsPopulated, tagsIsPopulated,
@ -59,7 +60,8 @@ const selectIsPopulated = createSelector(
qualityProfilesIsPopulated, qualityProfilesIsPopulated,
metadataProfilesIsPopulated, metadataProfilesIsPopulated,
importListsIsPopulated, importListsIsPopulated,
systemStatusIsPopulated systemStatusIsPopulated,
translationsIsPopulated
) => { ) => {
return ( return (
customFiltersIsPopulated && customFiltersIsPopulated &&
@ -69,7 +71,8 @@ const selectIsPopulated = createSelector(
qualityProfilesIsPopulated && qualityProfilesIsPopulated &&
metadataProfilesIsPopulated && metadataProfilesIsPopulated &&
importListsIsPopulated && importListsIsPopulated &&
systemStatusIsPopulated systemStatusIsPopulated &&
translationsIsPopulated
); );
} }
); );
@ -83,6 +86,7 @@ const selectErrors = createSelector(
(state) => state.settings.metadataProfiles.error, (state) => state.settings.metadataProfiles.error,
(state) => state.settings.importLists.error, (state) => state.settings.importLists.error,
(state) => state.system.status.error, (state) => state.system.status.error,
(state) => state.app.translations.error,
( (
customFiltersError, customFiltersError,
tagsError, tagsError,
@ -91,7 +95,8 @@ const selectErrors = createSelector(
qualityProfilesError, qualityProfilesError,
metadataProfilesError, metadataProfilesError,
importListsError, importListsError,
systemStatusError systemStatusError,
translationsError
) => { ) => {
const hasError = !!( const hasError = !!(
customFiltersError || customFiltersError ||
@ -101,7 +106,8 @@ const selectErrors = createSelector(
qualityProfilesError || qualityProfilesError ||
metadataProfilesError || metadataProfilesError ||
importListsError || importListsError ||
systemStatusError systemStatusError ||
translationsError
); );
return { return {
@ -113,7 +119,8 @@ const selectErrors = createSelector(
qualityProfilesError, qualityProfilesError,
metadataProfilesError, metadataProfilesError,
importListsError, importListsError,
systemStatusError systemStatusError,
translationsError
}; };
} }
); );
@ -172,6 +179,9 @@ function createMapDispatchToProps(dispatch, props) {
dispatchFetchStatus() { dispatchFetchStatus() {
dispatch(fetchStatus()); dispatch(fetchStatus());
}, },
dispatchFetchTranslations() {
dispatch(fetchTranslations());
},
onResize(dimensions) { onResize(dimensions) {
dispatch(saveDimensions(dimensions)); dispatch(saveDimensions(dimensions));
}, },
@ -205,6 +215,7 @@ class PageConnector extends Component {
this.props.dispatchFetchImportLists(); this.props.dispatchFetchImportLists();
this.props.dispatchFetchUISettings(); this.props.dispatchFetchUISettings();
this.props.dispatchFetchStatus(); this.props.dispatchFetchStatus();
this.props.dispatchFetchTranslations();
} }
} }
@ -220,7 +231,6 @@ class PageConnector extends Component {
render() { render() {
const { const {
hasTranslationsError,
isPopulated, isPopulated,
hasError, hasError,
dispatchFetchArtist, dispatchFetchArtist,
@ -231,15 +241,15 @@ class PageConnector extends Component {
dispatchFetchImportLists, dispatchFetchImportLists,
dispatchFetchUISettings, dispatchFetchUISettings,
dispatchFetchStatus, dispatchFetchStatus,
dispatchFetchTranslations,
...otherProps ...otherProps
} = this.props; } = this.props;
if (hasTranslationsError || hasError || !this.state.isLocalStorageSupported) { if (hasError || !this.state.isLocalStorageSupported) {
return ( return (
<ErrorPage <ErrorPage
{...this.state} {...this.state}
{...otherProps} {...otherProps}
hasTranslationsError={hasTranslationsError}
/> />
); );
} }
@ -260,7 +270,6 @@ class PageConnector extends Component {
} }
PageConnector.propTypes = { PageConnector.propTypes = {
hasTranslationsError: PropTypes.bool.isRequired,
isPopulated: PropTypes.bool.isRequired, isPopulated: PropTypes.bool.isRequired,
hasError: PropTypes.bool.isRequired, hasError: PropTypes.bool.isRequired,
isSidebarVisible: PropTypes.bool.isRequired, isSidebarVisible: PropTypes.bool.isRequired,
@ -273,6 +282,7 @@ PageConnector.propTypes = {
dispatchFetchImportLists: PropTypes.func.isRequired, dispatchFetchImportLists: PropTypes.func.isRequired,
dispatchFetchUISettings: PropTypes.func.isRequired, dispatchFetchUISettings: PropTypes.func.isRequired,
dispatchFetchStatus: PropTypes.func.isRequired, dispatchFetchStatus: PropTypes.func.isRequired,
dispatchFetchTranslations: PropTypes.func.isRequired,
onSidebarVisibleChange: PropTypes.func.isRequired onSidebarVisibleChange: PropTypes.func.isRequired
}; };

@ -21,24 +21,24 @@ const SIDEBAR_WIDTH = parseInt(dimensions.sidebarWidth);
const links = [ const links = [
{ {
iconName: icons.ARTIST_CONTINUING, iconName: icons.ARTIST_CONTINUING,
title: translate('Library'), title: () => translate('Library'),
to: '/', to: '/',
alias: '/artist', alias: '/artist',
children: [ children: [
{ {
title: translate('AddNew'), title: () => translate('AddNew'),
to: '/add/search' to: '/add/search'
}, },
{ {
title: translate('MassEditor'), title: () => translate('MassEditor'),
to: '/artisteditor' to: '/artisteditor'
}, },
{ {
title: translate('AlbumStudio'), title: () => translate('AlbumStudio'),
to: '/albumstudio' to: '/albumstudio'
}, },
{ {
title: translate('UnmappedFiles'), title: () => translate('UnmappedFiles'),
to: '/unmapped' to: '/unmapped'
} }
] ]
@ -46,26 +46,26 @@ const links = [
{ {
iconName: icons.CALENDAR, iconName: icons.CALENDAR,
title: translate('Calendar'), title: () => translate('Calendar'),
to: '/calendar' to: '/calendar'
}, },
{ {
iconName: icons.ACTIVITY, iconName: icons.ACTIVITY,
title: translate('Activity'), title: () => translate('Activity'),
to: '/activity/queue', to: '/activity/queue',
children: [ children: [
{ {
title: translate('Queue'), title: () => translate('Queue'),
to: '/activity/queue', to: '/activity/queue',
statusComponent: QueueStatusConnector statusComponent: QueueStatusConnector
}, },
{ {
title: translate('History'), title: () => translate('History'),
to: '/activity/history' to: '/activity/history'
}, },
{ {
title: translate('Blocklist'), title: () => translate('Blocklist'),
to: '/activity/blocklist' to: '/activity/blocklist'
} }
] ]
@ -73,15 +73,15 @@ const links = [
{ {
iconName: icons.WARNING, iconName: icons.WARNING,
title: translate('Wanted'), title: () => translate('Wanted'),
to: '/wanted/missing', to: '/wanted/missing',
children: [ children: [
{ {
title: translate('Missing'), title: () => translate('Missing'),
to: '/wanted/missing' to: '/wanted/missing'
}, },
{ {
title: translate('CutoffUnmet'), title: () => translate('CutoffUnmet'),
to: '/wanted/cutoffunmet' to: '/wanted/cutoffunmet'
} }
] ]
@ -89,55 +89,55 @@ const links = [
{ {
iconName: icons.SETTINGS, iconName: icons.SETTINGS,
title: translate('Settings'), title: () => translate('Settings'),
to: '/settings', to: '/settings',
children: [ children: [
{ {
title: translate('MediaManagement'), title: () => translate('MediaManagement'),
to: '/settings/mediamanagement' to: '/settings/mediamanagement'
}, },
{ {
title: translate('Profiles'), title: () => translate('Profiles'),
to: '/settings/profiles' to: '/settings/profiles'
}, },
{ {
title: translate('Quality'), title: () => translate('Quality'),
to: '/settings/quality' to: '/settings/quality'
}, },
{ {
title: translate('CustomFormats'), title: () => translate('CustomFormats'),
to: '/settings/customformats' to: '/settings/customformats'
}, },
{ {
title: translate('Indexers'), title: () => translate('Indexers'),
to: '/settings/indexers' to: '/settings/indexers'
}, },
{ {
title: translate('DownloadClients'), title: () => translate('DownloadClients'),
to: '/settings/downloadclients' to: '/settings/downloadclients'
}, },
{ {
title: translate('ImportLists'), title: () => translate('ImportLists'),
to: '/settings/importlists' to: '/settings/importlists'
}, },
{ {
title: translate('Connect'), title: () => translate('Connect'),
to: '/settings/connect' to: '/settings/connect'
}, },
{ {
title: translate('Metadata'), title: () => translate('Metadata'),
to: '/settings/metadata' to: '/settings/metadata'
}, },
{ {
title: translate('Tags'), title: () => translate('Tags'),
to: '/settings/tags' to: '/settings/tags'
}, },
{ {
title: translate('General'), title: () => translate('General'),
to: '/settings/general' to: '/settings/general'
}, },
{ {
title: translate('UI'), title: () => translate('UI'),
to: '/settings/ui' to: '/settings/ui'
} }
] ]
@ -145,32 +145,32 @@ const links = [
{ {
iconName: icons.SYSTEM, iconName: icons.SYSTEM,
title: translate('System'), title: () => translate('System'),
to: '/system/status', to: '/system/status',
children: [ children: [
{ {
title: translate('Status'), title: () => translate('Status'),
to: '/system/status', to: '/system/status',
statusComponent: HealthStatusConnector statusComponent: HealthStatusConnector
}, },
{ {
title: translate('Tasks'), title: () => translate('Tasks'),
to: '/system/tasks' to: '/system/tasks'
}, },
{ {
title: translate('Backup'), title: () => translate('Backup'),
to: '/system/backup' to: '/system/backup'
}, },
{ {
title: translate('Updates'), title: () => translate('Updates'),
to: '/system/updates' to: '/system/updates'
}, },
{ {
title: translate('Events'), title: () => translate('Events'),
to: '/system/events' to: '/system/events'
}, },
{ {
title: translate('LogFiles'), title: () => translate('LogFiles'),
to: '/system/logs/files' to: '/system/logs/files'
} }
] ]

@ -27,9 +27,25 @@ interface ManageDownloadClientsEditModalContentProps {
const NO_CHANGE = 'noChange'; const NO_CHANGE = 'noChange';
const enableOptions = [ const enableOptions = [
{ key: NO_CHANGE, value: translate('NoChange'), disabled: true }, {
{ key: 'enabled', value: translate('Enabled') }, key: NO_CHANGE,
{ key: 'disabled', value: translate('Disabled') }, get value() {
return translate('NoChange');
},
disabled: true,
},
{
key: 'enabled',
get value() {
return translate('Enabled');
},
},
{
key: 'disabled',
get value() {
return translate('Disabled');
},
},
]; ];
function ManageDownloadClientsEditModalContent( function ManageDownloadClientsEditModalContent(

@ -36,37 +36,49 @@ type OnSelectedChangeCallback = React.ComponentProps<
const COLUMNS = [ const COLUMNS = [
{ {
name: 'name', name: 'name',
label: translate('Name'), get label() {
return translate('Name');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },
{ {
name: 'implementation', name: 'implementation',
label: translate('Implementation'), get label() {
return translate('Implementation');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },
{ {
name: 'enable', name: 'enable',
label: translate('Enabled'), get label() {
return translate('Enabled');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },
{ {
name: 'priority', name: 'priority',
label: translate('Priority'), get label() {
return translate('Priority');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },
{ {
name: 'removeCompletedDownloads', name: 'removeCompletedDownloads',
label: translate('RemoveCompleted'), get label() {
return translate('RemoveCompleted');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },
{ {
name: 'removeFailedDownloads', name: 'removeFailedDownloads',
label: translate('RemoveFailed'), get label() {
return translate('RemoveFailed');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },

@ -72,9 +72,24 @@ function TagsModalContent(props: TagsModalContentProps) {
}, [tags, applyTags, onApplyTagsPress]); }, [tags, applyTags, onApplyTagsPress]);
const applyTagsOptions = [ const applyTagsOptions = [
{ key: 'add', value: translate('Add') }, {
{ key: 'remove', value: translate('Remove') }, key: 'add',
{ key: 'replace', value: translate('Replace') }, get value() {
return translate('Add');
},
},
{
key: 'remove',
get value() {
return translate('Remove');
},
},
{
key: 'replace',
get value() {
return translate('Replace');
},
},
]; ];
return ( return (

@ -26,9 +26,25 @@ interface ManageImportListsEditModalContentProps {
const NO_CHANGE = 'noChange'; const NO_CHANGE = 'noChange';
const autoAddOptions = [ const autoAddOptions = [
{ key: NO_CHANGE, value: translate('NoChange'), disabled: true }, {
{ key: 'enabled', value: translate('Enabled') }, key: NO_CHANGE,
{ key: 'disabled', value: translate('Disabled') }, get value() {
return translate('NoChange');
},
disabled: true,
},
{
key: 'enabled',
get value() {
return translate('Enabled');
},
},
{
key: 'disabled',
get value() {
return translate('Disabled');
},
},
]; ];
function ManageImportListsEditModalContent( function ManageImportListsEditModalContent(

@ -36,37 +36,49 @@ type OnSelectedChangeCallback = React.ComponentProps<
const COLUMNS = [ const COLUMNS = [
{ {
name: 'name', name: 'name',
label: translate('Name'), get label() {
return translate('Name');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },
{ {
name: 'implementation', name: 'implementation',
label: translate('Implementation'), get label() {
return translate('Implementation');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },
{ {
name: 'qualityProfileId', name: 'qualityProfileId',
label: translate('QualityProfile'), get label() {
return translate('QualityProfile');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },
{ {
name: 'rootFolderPath', name: 'rootFolderPath',
label: translate('RootFolder'), get label() {
return translate('RootFolder');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },
{ {
name: 'enableAutomaticAdd', name: 'enableAutomaticAdd',
label: translate('AutoAdd'), get label() {
return translate('AutoAdd');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },
{ {
name: 'tags', name: 'tags',
label: translate('Tags'), get label() {
return translate('Tags');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },

@ -70,9 +70,24 @@ function TagsModalContent(props: TagsModalContentProps) {
}, [tags, applyTags, onApplyTagsPress]); }, [tags, applyTags, onApplyTagsPress]);
const applyTagsOptions = [ const applyTagsOptions = [
{ key: 'add', value: translate('Add') }, {
{ key: 'remove', value: translate('Remove') }, key: 'add',
{ key: 'replace', value: translate('Replace') }, get value() {
return translate('Add');
},
},
{
key: 'remove',
get value() {
return translate('Remove');
},
},
{
key: 'replace',
get value() {
return translate('Replace');
},
},
]; ];
return ( return (

@ -27,9 +27,25 @@ interface ManageIndexersEditModalContentProps {
const NO_CHANGE = 'noChange'; const NO_CHANGE = 'noChange';
const enableOptions = [ const enableOptions = [
{ key: NO_CHANGE, value: translate('NoChange'), disabled: true }, {
{ key: 'enabled', value: translate('Enabled') }, key: NO_CHANGE,
{ key: 'disabled', value: translate('Disabled') }, get value() {
return translate('NoChange');
},
disabled: true,
},
{
key: 'enabled',
get value() {
return translate('Enabled');
},
},
{
key: 'disabled',
get value() {
return translate('Disabled');
},
},
]; ];
function ManageIndexersEditModalContent( function ManageIndexersEditModalContent(

@ -36,43 +36,57 @@ type OnSelectedChangeCallback = React.ComponentProps<
const COLUMNS = [ const COLUMNS = [
{ {
name: 'name', name: 'name',
label: translate('Name'), get label() {
return translate('Name');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },
{ {
name: 'implementation', name: 'implementation',
label: translate('Implementation'), get label() {
return translate('Implementation');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },
{ {
name: 'enableRss', name: 'enableRss',
label: translate('EnableRSS'), get label() {
return translate('EnableRSS');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },
{ {
name: 'enableAutomaticSearch', name: 'enableAutomaticSearch',
label: translate('EnableAutomaticSearch'), get label() {
return translate('EnableAutomaticSearch');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },
{ {
name: 'enableInteractiveSearch', name: 'enableInteractiveSearch',
label: translate('EnableInteractiveSearch'), get label() {
return translate('EnableInteractiveSearch');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },
{ {
name: 'priority', name: 'priority',
label: translate('Priority'), get label() {
return translate('Priority');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },
{ {
name: 'tags', name: 'tags',
label: translate('Tags'), get label() {
return translate('Tags');
},
isSortable: true, isSortable: true,
isVisible: true, isVisible: true,
}, },

@ -70,9 +70,24 @@ function TagsModalContent(props: TagsModalContentProps) {
}, [tags, applyTags, onApplyTagsPress]); }, [tags, applyTags, onApplyTagsPress]);
const applyTagsOptions = [ const applyTagsOptions = [
{ key: 'add', value: translate('Add') }, {
{ key: 'remove', value: translate('Remove') }, key: 'add',
{ key: 'replace', value: translate('Replace') }, get value() {
return translate('Add');
},
},
{
key: 'remove',
get value() {
return translate('Remove');
},
},
{
key: 'replace',
get value() {
return translate('Replace');
},
},
]; ];
return ( return (

@ -4,6 +4,7 @@ import { createThunk, handleThunks } from 'Store/thunks';
import createAjaxRequest from 'Utilities/createAjaxRequest'; import createAjaxRequest from 'Utilities/createAjaxRequest';
import getSectionState from 'Utilities/State/getSectionState'; import getSectionState from 'Utilities/State/getSectionState';
import updateSectionState from 'Utilities/State/updateSectionState'; import updateSectionState from 'Utilities/State/updateSectionState';
import { fetchTranslations as fetchAppTranslations } from 'Utilities/String/translate';
import createHandleActions from './Creators/createHandleActions'; import createHandleActions from './Creators/createHandleActions';
function getDimensions(width, height) { function getDimensions(width, height) {
@ -41,7 +42,12 @@ export const defaultState = {
isReconnecting: false, isReconnecting: false,
isDisconnected: false, isDisconnected: false,
isRestarting: false, isRestarting: false,
isSidebarVisible: !getDimensions(window.innerWidth, window.innerHeight).isSmallScreen isSidebarVisible: !getDimensions(window.innerWidth, window.innerHeight).isSmallScreen,
translations: {
isFetching: true,
isPopulated: false,
error: null
}
}; };
// //
@ -53,6 +59,7 @@ export const SAVE_DIMENSIONS = 'app/saveDimensions';
export const SET_VERSION = 'app/setVersion'; export const SET_VERSION = 'app/setVersion';
export const SET_APP_VALUE = 'app/setAppValue'; export const SET_APP_VALUE = 'app/setAppValue';
export const SET_IS_SIDEBAR_VISIBLE = 'app/setIsSidebarVisible'; export const SET_IS_SIDEBAR_VISIBLE = 'app/setIsSidebarVisible';
export const FETCH_TRANSLATIONS = 'app/fetchTranslations';
export const PING_SERVER = 'app/pingServer'; export const PING_SERVER = 'app/pingServer';
@ -66,6 +73,7 @@ export const setAppValue = createAction(SET_APP_VALUE);
export const showMessage = createAction(SHOW_MESSAGE); export const showMessage = createAction(SHOW_MESSAGE);
export const hideMessage = createAction(HIDE_MESSAGE); export const hideMessage = createAction(HIDE_MESSAGE);
export const pingServer = createThunk(PING_SERVER); export const pingServer = createThunk(PING_SERVER);
export const fetchTranslations = createThunk(FETCH_TRANSLATIONS);
// //
// Helpers // Helpers
@ -127,6 +135,17 @@ function pingServerAfterTimeout(getState, dispatch) {
export const actionHandlers = handleThunks({ export const actionHandlers = handleThunks({
[PING_SERVER]: function(getState, payload, dispatch) { [PING_SERVER]: function(getState, payload, dispatch) {
pingServerAfterTimeout(getState, dispatch); pingServerAfterTimeout(getState, dispatch);
},
[FETCH_TRANSLATIONS]: async function(getState, payload, dispatch) {
const isFetchingComplete = await fetchAppTranslations();
dispatch(setAppValue({
translations: {
isFetching: false,
isPopulated: isFetchingComplete,
error: isFetchingComplete ? null : 'Failed to load translations from API'
}
}));
} }
}); });

@ -2,7 +2,6 @@ import { createBrowserHistory } from 'history';
import React from 'react'; import React from 'react';
import { render } from 'react-dom'; import { render } from 'react-dom';
import createAppStore from 'Store/createAppStore'; import createAppStore from 'Store/createAppStore';
import { fetchTranslations } from 'Utilities/String/translate';
import App from './App/App'; import App from './App/App';
import 'Diag/ConsoleApi'; import 'Diag/ConsoleApi';
@ -10,14 +9,9 @@ import 'Diag/ConsoleApi';
export async function bootstrap() { export async function bootstrap() {
const history = createBrowserHistory(); const history = createBrowserHistory();
const store = createAppStore(history); const store = createAppStore(history);
const hasTranslationsError = !(await fetchTranslations());
render( render(
<App <App store={store} history={history} />,
store={store}
history={history}
hasTranslationsError={hasTranslationsError}
/>,
document.getElementById('root') document.getElementById('root')
); );
} }

Loading…
Cancel
Save