Skip to content

TagSpaces is an offline, open source, document manager with tagging support

change language from settings reflect to components (#1500)

Stanimir6dbf2a3d6f73
diff --git a/app/components/CustomLogo.tsx b/app/components/CustomLogo.tsx
index 0060b53a3..27a10f05e 100644
--- a/app/components/CustomLogo.tsx
+++ b/app/components/CustomLogo.tsx
@@ -31,6 +31,7 @@ import LogoIcon from '../assets/images/icon100x100.svg';
import { actions as AppActions } from '../reducers/app';
import i18n from '../services/i18n';
import versionMeta from '../version.json';
+import { getCurrentLanguage } from '-/reducers/settings';
const AppVersionBadge = withStyles(theme => ({
badge: {
@@ -93,6 +94,10 @@ function CustomLogo(props: Props) {
);
}
+function mapStateToProps(state) {
+ return { language: getCurrentLanguage(state) };
+}
+
function mapActionCreatorsToProps(dispatch) {
return bindActionCreators(
{
@@ -102,4 +107,4 @@ function mapActionCreatorsToProps(dispatch) {
);
}
-export default connect(undefined, mapActionCreatorsToProps)(CustomLogo);
+export default connect(mapStateToProps, mapActionCreatorsToProps)(CustomLogo);
diff --git a/app/components/EntryContainer.tsx b/app/components/EntryContainer.tsx
index cbb0d5519..4ef4d5c7e 100644
--- a/app/components/EntryContainer.tsx
+++ b/app/components/EntryContainer.tsx
@@ -68,7 +68,8 @@ import {
actions as SettingsActions,
isDesktopMode,
getKeyBindingObject,
- getMapTileServer
+ getMapTileServer,
+ getCurrentLanguage
} from '-/reducers/settings';
import TaggingActions from '-/reducers/tagging-actions';
import {
@@ -1171,7 +1172,8 @@ function mapStateToProps(state) {
isReadOnlyMode: isReadOnlyMode(state),
keyBindings: getKeyBindingObject(state),
isDesktopMode: isDesktopMode(state),
- tileServer: getMapTileServer(state)
+ tileServer: getMapTileServer(state),
+ language: getCurrentLanguage(state)
};
}
@@ -1203,6 +1205,7 @@ function mapActionCreatorsToProps(dispatch) {
}
const areEqual = (prevProp, nextProp) =>
// JSON.stringify(nextProp.theme) === JSON.stringify(prevProp.theme) &&
+ nextProp.language === prevProp.language &&
nextProp.settings.currentTheme === prevProp.settings.currentTheme &&
nextProp.settings.entrySplitSize === prevProp.settings.entrySplitSize &&
JSON.stringify(nextProp.openedFiles) === JSON.stringify(prevProp.openedFiles);
diff --git a/app/components/FileView.tsx b/app/components/FileView.tsx
index ac6eda8ae..d1bf5d936 100644
--- a/app/components/FileView.tsx
+++ b/app/components/FileView.tsx
@@ -18,11 +18,12 @@
import React, { MutableRefObject } from 'react';
import { withStyles } from '@material-ui/core/styles';
-import Fab from '@material-ui/core/Fab';
import CloseIcon from '@material-ui/icons/Close';
import i18n from '-/services/i18n';
import { OpenedEntry } from '-/reducers/app';
import useEventListener from '-/utils/useEventListener';
+import { connect } from 'react-redux';
+import { getCurrentLanguage } from '-/reducers/settings';
interface Props {
openedFile: OpenedEntry;
@@ -138,6 +139,7 @@ function FileView(props: Props) {
}
const areEqual = (prevProp, nextProp) =>
+ nextProp.language === prevProp.language &&
nextProp.openedFile.path === prevProp.openedFile.path &&
nextProp.openedFile.url === prevProp.openedFile.url &&
nextProp.openedFile.editMode === prevProp.openedFile.editMode &&
@@ -148,7 +150,10 @@ const areEqual = (prevProp, nextProp) =>
prevProp.openedFile.editMode === true) ||
nextProp.openedFile.editMode === prevProp.openedFile.editMode); */
-export default React.memo(
- withStyles(undefined, { withTheme: true })(FileView),
- areEqual
+function mapStateToProps(state) {
+ return { language: getCurrentLanguage(state) };
+}
+
+export default connect(mapStateToProps)(
+ React.memo(withStyles(undefined, { withTheme: true })(FileView), areEqual)
);
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsx
index d17ecc540..6cd2ee30c 100644
--- a/app/components/FolderContainer.tsx
+++ b/app/components/FolderContainer.tsx
@@ -39,9 +39,10 @@ import i18n from '../services/i18n';
import {
getMaxSearchResults,
getDesktopMode,
- // getKeyBindingObject,
+ getCurrentLanguage,
getDefaultPerspective
} from '-/reducers/settings';
+
import {
actions as AppActions,
getDirectoryContent,
@@ -241,6 +242,7 @@ interface Props {
setSearchQuery: (searchQuery: TS.SearchQuery) => void;
openCurrentDirectory: () => void;
openURLExternally?: (url: string, skipConfirmation: boolean) => void;
+ language: string;
// keyBindings: Array<any>;
}
@@ -721,6 +723,7 @@ function mapStateToProps(state) {
maxSearchResults: getMaxSearchResults(state),
isDesktopMode: getDesktopMode(state),
isReadOnlyMode: isReadOnlyMode(state),
+ language: getCurrentLanguage(state),
progress: getProgress(state),
searchQuery: getSearchQuery(state),
// keyBindings: getKeyBindingObject(state),
@@ -773,6 +776,8 @@ const areEqual = (prevProp: Props, nextProp: Props) =>
JSON.stringify(nextProp.theme) === JSON.stringify(prevProp.theme) &&
nextProp.windowWidth === prevProp.windowWidth &&
nextProp.windowHeight === prevProp.windowHeight &&
+ nextProp.language === prevProp.language &&
+ nextProp.windowHeight === prevProp.windowHeight &&
nextProp.searchQuery === prevProp.searchQuery;
export default connect(
diff --git a/app/components/HelpFeedbackPanel.tsx b/app/components/HelpFeedbackPanel.tsx
index ad0ba286f..3bfbe0db3 100644
--- a/app/components/HelpFeedbackPanel.tsx
+++ b/app/components/HelpFeedbackPanel.tsx
@@ -41,6 +41,8 @@ import AppConfig from '@tagspaces/tagspaces-platforms/AppConfig';
import styles from './SidePanels.css';
import i18n from '../services/i18n';
import Links from '-/links';
+import { connect } from 'react-redux';
+import { getCurrentLanguage } from '-/reducers/settings';
interface Props {
classes?: any;
@@ -236,4 +238,9 @@ function HelpFeedbackPanel(props: Props) {
);
}
-export default withStyles(styles, { withTheme: true })(HelpFeedbackPanel);
+function mapStateToProps(state) {
+ return { language: getCurrentLanguage(state) };
+}
+export default connect(mapStateToProps)(
+ withStyles(styles, { withTheme: true })(HelpFeedbackPanel)
+);
diff --git a/app/components/LocationManager.tsx b/app/components/LocationManager.tsx
index 2625f334e..f70307973 100644
--- a/app/components/LocationManager.tsx
+++ b/app/components/LocationManager.tsx
@@ -32,6 +32,7 @@ import {
} from '../reducers/locations';
import { actions as AppActions, isLoading } from '../reducers/app';
import {
+ getCurrentLanguage,
getPersistTagsInSidecarFile,
isDesktopMode
} from '-/reducers/settings';
@@ -280,7 +281,8 @@ function mapStateToProps(state) {
locations: getLocations(state),
isDesktop: isDesktopMode(state),
isLoading: isLoading(state),
- isPersistTagsInSidecar: getPersistTagsInSidecarFile(state)
+ isPersistTagsInSidecar: getPersistTagsInSidecarFile(state),
+ language: getCurrentLanguage(state)
};
}
diff --git a/app/components/LocationView.tsx b/app/components/LocationView.tsx
index 72f45cc49..ebedc9a91 100644
--- a/app/components/LocationView.tsx
+++ b/app/components/LocationView.tsx
@@ -47,7 +47,10 @@ import IOActions from '../reducers/io-actions';
import DirectoryTreeView, {
DirectoryTreeViewRef
} from '-/components/DirectoryTreeView';
-import { getShowUnixHiddenEntries } from '-/reducers/settings';
+import {
+ getCurrentLanguage,
+ getShowUnixHiddenEntries
+} from '-/reducers/settings';
import LocationContextMenu from '-/components/menus/LocationContextMenu';
import { TS } from '-/tagspaces.namespace';
@@ -353,7 +356,8 @@ function mapStateToProps(state) {
return {
currentLocationId: getCurrentLocationId(state),
isReadOnlyMode: isReadOnlyMode(state),
- showUnixHiddenEntries: getShowUnixHiddenEntries(state)
+ showUnixHiddenEntries: getShowUnixHiddenEntries(state),
+ language: getCurrentLanguage(state)
};
}
diff --git a/app/components/MobileNavigation.tsx b/app/components/MobileNavigation.tsx
index 7e8bf06da..a0409cede 100644
--- a/app/components/MobileNavigation.tsx
+++ b/app/components/MobileNavigation.tsx
@@ -62,7 +62,11 @@ import {
getDirectoryPath
} from '../reducers/app';
import LoadingLazy from './LoadingLazy';
-import { actions as SettingsActions, isFirstRun } from '../reducers/settings';
+import {
+ actions as SettingsActions,
+ getCurrentLanguage,
+ isFirstRun
+} from '../reducers/settings';
import Links from '-/links';
import StoredSearches from '-/components/StoredSearches';
import UserDetailsPopover from '-/components/UserDetailsPopover';
@@ -428,7 +432,8 @@ function mapStateToProps(state) {
isHelpFeedbackPanelOpened: isHelpFeedbackPanelOpened(state),
isReadOnlyMode: isReadOnlyMode(state),
directoryPath: getDirectoryPath(state),
- user: state.app.user
+ user: state.app.user,
+ language: getCurrentLanguage(state)
};
}
diff --git a/app/components/NoTileServer.tsx b/app/components/NoTileServer.tsx
index be651d8f4..f9bdf92d1 100644
--- a/app/components/NoTileServer.tsx
+++ b/app/components/NoTileServer.tsx
@@ -1,5 +1,7 @@
import React from 'react';
import i18n from '-/services/i18n';
+import { connect } from 'react-redux';
+import { getCurrentLanguage } from '-/reducers/settings';
function NoTileServer() {
return (
@@ -10,4 +12,8 @@ function NoTileServer() {
);
}
-export default NoTileServer;
+function mapStateToProps(state) {
+ return { language: getCurrentLanguage(state) };
+}
+
+export default connect(mapStateToProps)(NoTileServer);
diff --git a/app/components/PathBreadcrumbs.tsx b/app/components/PathBreadcrumbs.tsx
index eedbbd93a..b6a1bc058 100644
--- a/app/components/PathBreadcrumbs.tsx
+++ b/app/components/PathBreadcrumbs.tsx
@@ -30,6 +30,8 @@ import {
import i18n from '../services/i18n';
import DirectoryMenu from './menus/DirectoryMenu';
import { TS } from '-/tagspaces.namespace';
+import { connect } from 'react-redux';
+import { getCurrentLanguage } from '-/reducers/settings';
// @ts-ignore
const StyledBreadcrumb = withStyles((theme: Theme) => ({
@@ -80,7 +82,7 @@ function handleClick(event: React.MouseEvent<Element, MouseEvent>) {
console.info('You clicked a breadcrumb.');
}
-export default function PathBreadcrumbs(props: Props) {
+function PathBreadcrumbs(props: Props) {
let pathParts: Array<string> = [];
const [
@@ -230,3 +232,7 @@ export default function PathBreadcrumbs(props: Props) {
</>
);
}
+function mapStateToProps(state) {
+ return { language: getCurrentLanguage(state) };
+}
+export default connect(mapStateToProps)(PathBreadcrumbs);
diff --git a/app/components/PerspectiveSelector.tsx b/app/components/PerspectiveSelector.tsx
index cdb6ded5a..02ca8059b 100644
--- a/app/components/PerspectiveSelector.tsx
+++ b/app/components/PerspectiveSelector.tsx
@@ -26,6 +26,8 @@ import MenuItem from '@material-ui/core/MenuItem';
import { AvailablePerspectives, PerspectiveIDs } from '-/perspectives';
import i18n from '../services/i18n';
import { Pro } from '-/pro';
+import { connect } from 'react-redux';
+import { getCurrentLanguage } from '-/reducers/settings';
function PerspectiveSelector(props) {
const { defaultValue, onChange, testId } = props;
@@ -80,4 +82,7 @@ function PerspectiveSelector(props) {
);
}
-export default PerspectiveSelector;
+function mapStateToProps(state) {
+ return { language: getCurrentLanguage(state) };
+}
+export default connect(mapStateToProps)(PerspectiveSelector);
diff --git a/app/components/SearchInline.tsx b/app/components/SearchInline.tsx
index cbc1a17a4..3533db300 100644
--- a/app/components/SearchInline.tsx
+++ b/app/components/SearchInline.tsx
@@ -42,7 +42,8 @@ import {
import {
isDesktopMode,
getMaxSearchResults,
- getShowUnixHiddenEntries
+ getShowUnixHiddenEntries,
+ getCurrentLanguage
} from '-/reducers/settings';
import i18n from '-/services/i18n';
import { FileTypeGroups } from '-/services/search';
@@ -492,7 +493,8 @@ function mapStateToProps(state) {
currentDirectory: getDirectoryPath(state),
indexedEntriesCount: getIndexedEntriesCount(state),
maxSearchResults: getMaxSearchResults(state),
- showUnixHiddenEntries: getShowUnixHiddenEntries(state)
+ showUnixHiddenEntries: getShowUnixHiddenEntries(state),
+ language: getCurrentLanguage(state)
};
}
@@ -512,6 +514,7 @@ function mapDispatchToProps(dispatch) {
}
const areEqual = (prevProp, nextProp) =>
+ nextProp.language === prevProp.language &&
nextProp.indexing === prevProp.indexing &&
nextProp.searchQuery === prevProp.searchQuery &&
nextProp.currentDirectory === prevProp.currentDirectory &&
diff --git a/app/components/SearchPopover.tsx b/app/components/SearchPopover.tsx
index 58c0d214f..d1d70432a 100644
--- a/app/components/SearchPopover.tsx
+++ b/app/components/SearchPopover.tsx
@@ -61,6 +61,7 @@ import {
getSearchQuery
} from '../reducers/location-index';
import {
+ getCurrentLanguage,
getMaxSearchResults,
getShowUnixHiddenEntries
} from '-/reducers/settings';
@@ -1035,7 +1036,8 @@ function mapStateToProps(state) {
indexedEntriesCount: getIndexedEntriesCount(state),
maxSearchResults: getMaxSearchResults(state),
searches: getSearches(state),
- showUnixHiddenEntries: getShowUnixHiddenEntries(state)
+ showUnixHiddenEntries: getShowUnixHiddenEntries(state),
+ language: getCurrentLanguage(state)
};
}
@@ -1053,6 +1055,7 @@ function mapDispatchToProps(dispatch) {
}
const areEqual = (prevProp, nextProp) =>
+ nextProp.language === prevProp.language &&
nextProp.indexing === prevProp.indexing &&
nextProp.searchQuery === prevProp.searchQuery &&
nextProp.currentDirectory === prevProp.currentDirectory &&
diff --git a/app/components/StoredSearches.tsx b/app/components/StoredSearches.tsx
index eaac4b3b6..55d0b6d3c 100644
--- a/app/components/StoredSearches.tsx
+++ b/app/components/StoredSearches.tsx
@@ -33,7 +33,10 @@ import {
actions as LocationIndexActions,
getSearchQuery
} from '-/reducers/location-index';
-import { getShowUnixHiddenEntries } from '-/reducers/settings';
+import {
+ getCurrentLanguage,
+ getShowUnixHiddenEntries
+} from '-/reducers/settings';
import i18n from '../services/i18n';
import { Pro } from '../pro';
import { actions as SearchActions, getSearches } from '-/reducers/searches';
@@ -280,6 +283,7 @@ function StoredSearches(props: Props) {
function mapStateToProps(state) {
return {
+ language: getCurrentLanguage(state),
searchQuery: getSearchQuery(state),
searches: getSearches(state),
showUnixHiddenEntries: getShowUnixHiddenEntries(state)
@@ -300,6 +304,7 @@ function mapDispatchToProps(dispatch) {
}
const areEqual = (prevProp, nextProp) =>
+ nextProp.language === prevProp.language &&
nextProp.indexing === prevProp.indexing &&
nextProp.searchQuery === prevProp.searchQuery &&
nextProp.currentDirectory === prevProp.currentDirectory &&
diff --git a/app/components/TagLibrary.tsx b/app/components/TagLibrary.tsx
index ada46e6e2..0359a7ff3 100644
--- a/app/components/TagLibrary.tsx
+++ b/app/components/TagLibrary.tsx
@@ -46,6 +46,7 @@ import TaggingActions from '../reducers/tagging-actions';
import i18n from '../services/i18n';
import {
actions as SettingsActions,
+ getCurrentLanguage,
getTagColor,
getTagTextColor
} from '../reducers/settings';
@@ -477,7 +478,8 @@ function mapStateToProps(state) {
isReadOnly: isReadOnlyMode(state),
tagGroupCollapsed: state.settings.tagGroupCollapsed,
locations: getLocations(state),
- saveTagInLocation: state.settings.saveTagInLocation
+ saveTagInLocation: state.settings.saveTagInLocation,
+ language: getCurrentLanguage(state)
};
}
diff --git a/app/components/TagsPreview.tsx b/app/components/TagsPreview.tsx
index 7cbc329c1..df71508c7 100644
--- a/app/components/TagsPreview.tsx
+++ b/app/components/TagsPreview.tsx
@@ -21,7 +21,11 @@ import { connect } from 'react-redux';
import Tooltip from '@material-ui/core/Tooltip';
import { TS } from '-/tagspaces.namespace';
import { getAllTags, getTagColors } from '-/reducers/taglibrary';
-import { getTagColor, getTagTextColor } from '-/reducers/settings';
+import {
+ getCurrentLanguage,
+ getTagColor,
+ getTagTextColor
+} from '-/reducers/settings';
import i18n from '-/services/i18n';
interface Props {
@@ -81,7 +85,8 @@ function mapStateToProps(state) {
return {
allTags: getAllTags(state),
defaultBackgroundColor: getTagColor(state),
- defaultTextColor: getTagTextColor(state)
+ defaultTextColor: getTagTextColor(state),
+ language: getCurrentLanguage(state)
};
}
export default connect(mapStateToProps)(TagsPreview);
diff --git a/app/components/dialogs/settings/SettingsDialog.tsx b/app/components/dialogs/settings/SettingsDialog.tsx
index c777adad8..f0da3b7dc 100644
--- a/app/components/dialogs/settings/SettingsDialog.tsx
+++ b/app/components/dialogs/settings/SettingsDialog.tsx
@@ -37,7 +37,11 @@ import SettingsGeneral from '../settings/SettingsGeneral';
import SettingsKeyBindings from '../settings/SettingsKeyBindings';
import SettingsFileTypes from '../settings/SettingsFileTypes';
import i18n from '-/services/i18n';
-import { actions, getSupportedFileTypes } from '-/reducers/settings';
+import {
+ actions,
+ getCurrentLanguage,
+ getSupportedFileTypes
+} from '-/reducers/settings';
import { clearAllURLParams } from '-/utils/dom';
import SettingsAdvanced from '-/components/dialogs/settings/SettingsAdvanced';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
@@ -341,7 +345,8 @@ function SettingsDialog(props: Props) {
}
const mapStateToProps = state => ({
- supportedFileTypes: getSupportedFileTypes(state)
+ supportedFileTypes: getSupportedFileTypes(state),
+ language: getCurrentLanguage(state)
});
const mapDispatchToProps = dispatch => ({
diff --git a/app/components/dialogs/settings/SettingsGeneral.tsx b/app/components/dialogs/settings/SettingsGeneral.tsx
index 97b68674f..9e507d97f 100644
--- a/app/components/dialogs/settings/SettingsGeneral.tsx
+++ b/app/components/dialogs/settings/SettingsGeneral.tsx
@@ -133,13 +133,13 @@ function SettingsGeneral(props: Props) {
onChange={(event: any) => {
props.setLanguage(event.target.value);
PlatformIO.setLanguage(event.target.value);
- // TODO remove
- const { currentTheme } = props.settings;
- const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
- props.setCurrentTheme(newTheme);
- setTimeout(() => {
- props.setCurrentTheme(currentTheme);
- }, 500);
+ // TODO remove (language state is changed in settings reducer and components will be reloaded without this)
+ /* const { currentTheme } = props.settings;
+ const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
+ props.setCurrentTheme(newTheme);
+ setTimeout(() => {
+ props.setCurrentTheme(currentTheme);
+ }, 500); */
}}
input={<Input id="languageSelector" />}
>
diff --git a/app/reducers/settings.ts b/app/reducers/settings.ts
index b595f2f99..62ba116e0 100644
--- a/app/reducers/settings.ts
+++ b/app/reducers/settings.ts
@@ -189,7 +189,6 @@ export default (state: any = defaultSettings, action: any) => {
return { ...state, firstRun: action.firstRun };
}
case types.SET_LANGUAGE: {
- i18n.changeLanguage(action.language);
return { ...state, interfaceLanguage: action.language };
}
case types.SET_APPDATAPATH: {
@@ -459,7 +458,15 @@ export const actions = {
type: types.SET_REORDER_TAGS,
reorderTags
}),
- setLanguage: (language: string) => ({ type: types.SET_LANGUAGE, language }),
+ setLanguage: (language: string) => (dispatch: (action) => void) => {
+ return i18n.changeLanguage(language).then(() => {
+ dispatch(actions.setLanguageInt(language));
+ });
+ },
+ setLanguageInt: (language: string) => ({
+ type: types.SET_LANGUAGE,
+ language
+ }),
setUseDefaultLocation: (useDefaultLocation: boolean) => ({
type: types.SET_USEDEFAULTLOCATION,
useDefaultLocation